Statistics
| Branch: | Revision:

ffmpeg / libavcodec / vc1.c @ f8bed30d

History | View | Annotate | Download (36.3 KB)

1
/*
2
 * VC-1 and WMV3 decoder common code
3
 * Copyright (c) 2006-2007 Konstantin Shishkov
4
 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

    
23
/**
24
 * @file
25
 * VC-1 and WMV3 decoder common code
26
 *
27
 */
28
#include "internal.h"
29
#include "dsputil.h"
30
#include "avcodec.h"
31
#include "mpegvideo.h"
32
#include "vc1.h"
33
#include "vc1data.h"
34
#include "msmpeg4data.h"
35
#include "unary.h"
36
#include "simple_idct.h"
37

    
38
#undef NDEBUG
39
#include <assert.h>
40

    
41
/***********************************************************************/
42
/**
43
 * @defgroup vc1bitplane VC-1 Bitplane decoding
44
 * @see 8.7, p56
45
 * @{
46
 */
47

    
48
/**
49
 * Imode types
50
 * @{
51
 */
52
enum Imode {
53
    IMODE_RAW,
54
    IMODE_NORM2,
55
    IMODE_DIFF2,
56
    IMODE_NORM6,
57
    IMODE_DIFF6,
58
    IMODE_ROWSKIP,
59
    IMODE_COLSKIP
60
};
61
/** @} */ //imode defines
62

    
63
/** Decode rows by checking if they are skipped
64
 * @param plane Buffer to store decoded bits
65
 * @param[in] width Width of this buffer
66
 * @param[in] height Height of this buffer
67
 * @param[in] stride of this buffer
68
 */
69
static void decode_rowskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
70
    int x, y;
71

    
72
    for (y=0; y<height; y++){
73
        if (!get_bits1(gb)) //rowskip
74
            memset(plane, 0, width);
75
        else
76
            for (x=0; x<width; x++)
77
                plane[x] = get_bits1(gb);
78
        plane += stride;
79
    }
80
}
81

    
82
/** Decode columns by checking if they are skipped
83
 * @param plane Buffer to store decoded bits
84
 * @param[in] width Width of this buffer
85
 * @param[in] height Height of this buffer
86
 * @param[in] stride of this buffer
87
 * @todo FIXME: Optimize
88
 */
89
static void decode_colskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
90
    int x, y;
91

    
92
    for (x=0; x<width; x++){
93
        if (!get_bits1(gb)) //colskip
94
            for (y=0; y<height; y++)
95
                plane[y*stride] = 0;
96
        else
97
            for (y=0; y<height; y++)
98
                plane[y*stride] = get_bits1(gb);
99
        plane ++;
100
    }
101
}
102

    
103
/** Decode a bitplane's bits
104
 * @param data bitplane where to store the decode bits
105
 * @param[out] raw_flag pointer to the flag indicating that this bitplane is not coded explicitly
106
 * @param v VC-1 context for bit reading and logging
107
 * @return Status
108
 * @todo FIXME: Optimize
109
 */
110
static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
111
{
112
    GetBitContext *gb = &v->s.gb;
113

    
114
    int imode, x, y, code, offset;
115
    uint8_t invert, *planep = data;
116
    int width, height, stride;
117

    
118
    width = v->s.mb_width;
119
    height = v->s.mb_height;
120
    stride = v->s.mb_stride;
121
    invert = get_bits1(gb);
122
    imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
123

    
124
    *raw_flag = 0;
125
    switch (imode)
126
    {
127
    case IMODE_RAW:
128
        //Data is actually read in the MB layer (same for all tests == "raw")
129
        *raw_flag = 1; //invert ignored
130
        return invert;
131
    case IMODE_DIFF2:
132
    case IMODE_NORM2:
133
        if ((height * width) & 1)
134
        {
135
            *planep++ = get_bits1(gb);
136
            offset = 1;
137
        }
138
        else offset = 0;
139
        // decode bitplane as one long line
140
        for (y = offset; y < height * width; y += 2) {
141
            code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
142
            *planep++ = code & 1;
143
            offset++;
144
            if(offset == width) {
145
                offset = 0;
146
                planep += stride - width;
147
            }
148
            *planep++ = code >> 1;
149
            offset++;
150
            if(offset == width) {
151
                offset = 0;
152
                planep += stride - width;
153
            }
154
        }
155
        break;
156
    case IMODE_DIFF6:
157
    case IMODE_NORM6:
158
        if(!(height % 3) && (width % 3)) { // use 2x3 decoding
159
            for(y = 0; y < height; y+= 3) {
160
                for(x = width & 1; x < width; x += 2) {
161
                    code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
162
                    if(code < 0){
163
                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
164
                        return -1;
165
                    }
166
                    planep[x + 0] = (code >> 0) & 1;
167
                    planep[x + 1] = (code >> 1) & 1;
168
                    planep[x + 0 + stride] = (code >> 2) & 1;
169
                    planep[x + 1 + stride] = (code >> 3) & 1;
170
                    planep[x + 0 + stride * 2] = (code >> 4) & 1;
171
                    planep[x + 1 + stride * 2] = (code >> 5) & 1;
172
                }
173
                planep += stride * 3;
174
            }
175
            if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb);
176
        } else { // 3x2
177
            planep += (height & 1) * stride;
178
            for(y = height & 1; y < height; y += 2) {
179
                for(x = width % 3; x < width; x += 3) {
180
                    code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
181
                    if(code < 0){
182
                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
183
                        return -1;
184
                    }
185
                    planep[x + 0] = (code >> 0) & 1;
186
                    planep[x + 1] = (code >> 1) & 1;
187
                    planep[x + 2] = (code >> 2) & 1;
188
                    planep[x + 0 + stride] = (code >> 3) & 1;
189
                    planep[x + 1 + stride] = (code >> 4) & 1;
190
                    planep[x + 2 + stride] = (code >> 5) & 1;
191
                }
192
                planep += stride * 2;
193
            }
194
            x = width % 3;
195
            if(x) decode_colskip(data  ,             x, height    , stride, &v->s.gb);
196
            if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb);
197
        }
198
        break;
199
    case IMODE_ROWSKIP:
200
        decode_rowskip(data, width, height, stride, &v->s.gb);
201
        break;
202
    case IMODE_COLSKIP:
203
        decode_colskip(data, width, height, stride, &v->s.gb);
204
        break;
205
    default: break;
206
    }
207

    
208
    /* Applying diff operator */
209
    if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
210
    {
211
        planep = data;
212
        planep[0] ^= invert;
213
        for (x=1; x<width; x++)
214
            planep[x] ^= planep[x-1];
215
        for (y=1; y<height; y++)
216
        {
217
            planep += stride;
218
            planep[0] ^= planep[-stride];
219
            for (x=1; x<width; x++)
220
            {
221
                if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
222
                else                                 planep[x] ^= planep[x-1];
223
            }
224
        }
225
    }
226
    else if (invert)
227
    {
228
        planep = data;
229
        for (x=0; x<stride*height; x++) planep[x] = !planep[x]; //FIXME stride
230
    }
231
    return (imode<<1) + invert;
232
}
233

    
234
/** @} */ //Bitplane group
235

    
236
/***********************************************************************/
237
/** VOP Dquant decoding
238
 * @param v VC-1 Context
239
 */
240
static int vop_dquant_decoding(VC1Context *v)
241
{
242
    GetBitContext *gb = &v->s.gb;
243
    int pqdiff;
244

    
245
    //variable size
246
    if (v->dquant == 2)
247
    {
248
        pqdiff = get_bits(gb, 3);
249
        if (pqdiff == 7) v->altpq = get_bits(gb, 5);
250
        else v->altpq = v->pq + pqdiff + 1;
251
    }
252
    else
253
    {
254
        v->dquantfrm = get_bits1(gb);
255
        if ( v->dquantfrm )
256
        {
257
            v->dqprofile = get_bits(gb, 2);
258
            switch (v->dqprofile)
259
            {
260
            case DQPROFILE_SINGLE_EDGE:
261
            case DQPROFILE_DOUBLE_EDGES:
262
                v->dqsbedge = get_bits(gb, 2);
263
                break;
264
            case DQPROFILE_ALL_MBS:
265
                v->dqbilevel = get_bits1(gb);
266
                if(!v->dqbilevel)
267
                    v->halfpq = 0;
268
            default: break; //Forbidden ?
269
            }
270
            if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS)
271
            {
272
                pqdiff = get_bits(gb, 3);
273
                if (pqdiff == 7) v->altpq = get_bits(gb, 5);
274
                else v->altpq = v->pq + pqdiff + 1;
275
            }
276
        }
277
    }
278
    return 0;
279
}
280

    
281
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
282

    
283
static void simple_idct_put_rangered(uint8_t *dest, int line_size, DCTELEM *block)
284
{
285
    int i;
286
    ff_simple_idct(block);
287
    for (i = 0; i < 64; i++) block[i] = (block[i] - 64) << 1;
288
    ff_put_pixels_clamped_c(block, dest, line_size);
289
}
290

    
291
static void simple_idct_put_signed(uint8_t *dest, int line_size, DCTELEM *block)
292
{
293
    ff_simple_idct(block);
294
    ff_put_signed_pixels_clamped_c(block, dest, line_size);
295
}
296

    
297
static void simple_idct_put_signed_rangered(uint8_t *dest, int line_size, DCTELEM *block)
298
{
299
    int i;
300
    ff_simple_idct(block);
301
    for (i = 0; i < 64; i++) block[i] <<= 1;
302
    ff_put_signed_pixels_clamped_c(block, dest, line_size);
303
}
304

    
305
/**
306
 * Decode Simple/Main Profiles sequence header
307
 * @see Figure 7-8, p16-17
308
 * @param avctx Codec context
309
 * @param gb GetBit context initialized from Codec context extra_data
310
 * @return Status
311
 */
312
int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
313
{
314
    av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
315
    v->profile = get_bits(gb, 2);
316
    if (v->profile == PROFILE_COMPLEX)
317
    {
318
        av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");
319
    }
320

    
321
    if (v->profile == PROFILE_ADVANCED)
322
    {
323
        v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;
324
        v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;
325
        return decode_sequence_header_adv(v, gb);
326
    }
327
    else
328
    {
329
        v->zz_8x4 = wmv2_scantableA;
330
        v->zz_4x8 = wmv2_scantableB;
331
        v->res_y411   = get_bits1(gb);
332
        v->res_sprite = get_bits1(gb);
333
        if (v->res_y411)
334
        {
335
            av_log(avctx, AV_LOG_ERROR,
336
                   "Old interlaced mode is not supported\n");
337
            return -1;
338
        }
339
        if (v->res_sprite) {
340
            av_log(avctx, AV_LOG_ERROR, "WMVP is not fully supported\n");
341
        }
342
    }
343

    
344
    // (fps-2)/4 (->30)
345
    v->frmrtq_postproc = get_bits(gb, 3); //common
346
    // (bitrate-32kbps)/64kbps
347
    v->bitrtq_postproc = get_bits(gb, 5); //common
348
    v->s.loop_filter = get_bits1(gb); //common
349
    if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)
350
    {
351
        av_log(avctx, AV_LOG_ERROR,
352
               "LOOPFILTER shall not be enabled in Simple Profile\n");
353
    }
354
    if(v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
355
        v->s.loop_filter = 0;
356

    
357
    v->res_x8 = get_bits1(gb); //reserved
358
    v->multires = get_bits1(gb);
359
    v->res_fasttx = get_bits1(gb);
360
    if (!v->res_fasttx)
361
    {
362
        v->vc1dsp.vc1_inv_trans_8x8_add = ff_simple_idct_add;
363
        v->vc1dsp.vc1_inv_trans_8x8_put[0] = ff_simple_idct_put;
364
        v->vc1dsp.vc1_inv_trans_8x8_put[1] = simple_idct_put_rangered;
365
        v->vc1dsp.vc1_inv_trans_8x8_put_signed[0] = simple_idct_put_signed;
366
        v->vc1dsp.vc1_inv_trans_8x8_put_signed[1] = simple_idct_put_signed_rangered;
367
        v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;
368
        v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;
369
        v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;
370
        v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add;
371
        v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;
372
        v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;
373
        v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;
374
    }
375

    
376
    v->fastuvmc =  get_bits1(gb); //common
377
    if (!v->profile && !v->fastuvmc)
378
    {
379
        av_log(avctx, AV_LOG_ERROR,
380
               "FASTUVMC unavailable in Simple Profile\n");
381
        return -1;
382
    }
383
    v->extended_mv =  get_bits1(gb); //common
384
    if (!v->profile && v->extended_mv)
385
    {
386
        av_log(avctx, AV_LOG_ERROR,
387
               "Extended MVs unavailable in Simple Profile\n");
388
        return -1;
389
    }
390
    v->dquant =  get_bits(gb, 2); //common
391
    v->vstransform =  get_bits1(gb); //common
392

    
393
    v->res_transtab = get_bits1(gb);
394
    if (v->res_transtab)
395
    {
396
        av_log(avctx, AV_LOG_ERROR,
397
               "1 for reserved RES_TRANSTAB is forbidden\n");
398
        return -1;
399
    }
400

    
401
    v->overlap = get_bits1(gb); //common
402

    
403
    v->s.resync_marker = get_bits1(gb);
404
    v->rangered = get_bits1(gb);
405
    if (v->rangered && v->profile == PROFILE_SIMPLE)
406
    {
407
        av_log(avctx, AV_LOG_INFO,
408
               "RANGERED should be set to 0 in Simple Profile\n");
409
    }
410

    
411
    v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
412
    v->quantizer_mode = get_bits(gb, 2); //common
413

    
414
    v->finterpflag = get_bits1(gb); //common
415

    
416
    if (v->res_sprite) {
417
        v->s.avctx->width  = v->s.avctx->coded_width  = get_bits(gb, 11);
418
        v->s.avctx->height = v->s.avctx->coded_height = get_bits(gb, 11);
419
        skip_bits(gb, 5); //frame rate
420
        v->res_x8 = get_bits1(gb);
421
        if (get_bits1(gb)) { // something to do with DC VLC selection
422
            av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");
423
            return -1;
424
        }
425
        skip_bits(gb, 3); //slice code
426
        v->res_rtm_flag = 0;
427
    } else {
428
        v->res_rtm_flag = get_bits1(gb); //reserved
429
    }
430
    if (!v->res_rtm_flag)
431
    {
432
//            av_log(avctx, AV_LOG_ERROR,
433
//                   "0 for reserved RES_RTM_FLAG is forbidden\n");
434
        av_log(avctx, AV_LOG_ERROR,
435
               "Old WMV3 version detected, some frames may be decoded incorrectly\n");
436
        //return -1;
437
    }
438
    //TODO: figure out what they mean (always 0x402F)
439
    if(!v->res_fasttx) skip_bits(gb, 16);
440
    av_log(avctx, AV_LOG_DEBUG,
441
               "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
442
               "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
443
               "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
444
               "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
445
               v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
446
               v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
447
               v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
448
               v->dquant, v->quantizer_mode, avctx->max_b_frames
449
               );
450
    return 0;
451
}
452

    
453
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
454
{
455
    v->res_rtm_flag = 1;
456
    v->level = get_bits(gb, 3);
457
    if(v->level >= 5)
458
    {
459
        av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
460
    }
461
    v->chromaformat = get_bits(gb, 2);
462
    if (v->chromaformat != 1)
463
    {
464
        av_log(v->s.avctx, AV_LOG_ERROR,
465
               "Only 4:2:0 chroma format supported\n");
466
        return -1;
467
    }
468

    
469
    // (fps-2)/4 (->30)
470
    v->frmrtq_postproc = get_bits(gb, 3); //common
471
    // (bitrate-32kbps)/64kbps
472
    v->bitrtq_postproc = get_bits(gb, 5); //common
473
    v->postprocflag = get_bits1(gb); //common
474

    
475
    v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1;
476
    v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1;
477
    v->s.avctx->width = v->s.avctx->coded_width;
478
    v->s.avctx->height = v->s.avctx->coded_height;
479
    v->broadcast = get_bits1(gb);
480
    v->interlace = get_bits1(gb);
481
    v->tfcntrflag = get_bits1(gb);
482
    v->finterpflag = get_bits1(gb);
483
    skip_bits1(gb); // reserved
484

    
485
    v->s.h_edge_pos = v->s.avctx->coded_width;
486
    v->s.v_edge_pos = v->s.avctx->coded_height;
487

    
488
    av_log(v->s.avctx, AV_LOG_DEBUG,
489
               "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
490
               "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
491
               "TFCTRflag=%i, FINTERPflag=%i\n",
492
               v->level, v->frmrtq_postproc, v->bitrtq_postproc,
493
               v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
494
               v->tfcntrflag, v->finterpflag
495
               );
496

    
497
    v->psf = get_bits1(gb);
498
    if(v->psf) { //PsF, 6.1.13
499
        av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
500
        return -1;
501
    }
502
    v->s.max_b_frames = v->s.avctx->max_b_frames = 7;
503
    if(get_bits1(gb)) { //Display Info - decoding is not affected by it
504
        int w, h, ar = 0;
505
        av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
506
        v->s.avctx->width  = w = get_bits(gb, 14) + 1;
507
        v->s.avctx->height = h = get_bits(gb, 14) + 1;
508
        av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
509
        if(get_bits1(gb))
510
            ar = get_bits(gb, 4);
511
        if(ar && ar < 14){
512
            v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
513
        }else if(ar == 15){
514
            w = get_bits(gb, 8);
515
            h = get_bits(gb, 8);
516
            v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
517
        }
518
        av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", v->s.avctx->sample_aspect_ratio.num, v->s.avctx->sample_aspect_ratio.den);
519

    
520
        if(get_bits1(gb)){ //framerate stuff
521
            if(get_bits1(gb)) {
522
                v->s.avctx->time_base.num = 32;
523
                v->s.avctx->time_base.den = get_bits(gb, 16) + 1;
524
            } else {
525
                int nr, dr;
526
                nr = get_bits(gb, 8);
527
                dr = get_bits(gb, 4);
528
                if(nr && nr < 8 && dr && dr < 3){
529
                    v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1];
530
                    v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000;
531
                }
532
            }
533
        }
534

    
535
        if(get_bits1(gb)){
536
            v->color_prim = get_bits(gb, 8);
537
            v->transfer_char = get_bits(gb, 8);
538
            v->matrix_coef = get_bits(gb, 8);
539
        }
540
    }
541

    
542
    v->hrd_param_flag = get_bits1(gb);
543
    if(v->hrd_param_flag) {
544
        int i;
545
        v->hrd_num_leaky_buckets = get_bits(gb, 5);
546
        skip_bits(gb, 4); //bitrate exponent
547
        skip_bits(gb, 4); //buffer size exponent
548
        for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
549
            skip_bits(gb, 16); //hrd_rate[n]
550
            skip_bits(gb, 16); //hrd_buffer[n]
551
        }
552
    }
553
    return 0;
554
}
555

    
556
int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
557
{
558
    int i;
559

    
560
    av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
561
    v->broken_link = get_bits1(gb);
562
    v->closed_entry = get_bits1(gb);
563
    v->panscanflag = get_bits1(gb);
564
    v->refdist_flag = get_bits1(gb);
565
    v->s.loop_filter = get_bits1(gb);
566
    v->fastuvmc = get_bits1(gb);
567
    v->extended_mv = get_bits1(gb);
568
    v->dquant = get_bits(gb, 2);
569
    v->vstransform = get_bits1(gb);
570
    v->overlap = get_bits1(gb);
571
    v->quantizer_mode = get_bits(gb, 2);
572

    
573
    if(v->hrd_param_flag){
574
        for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
575
            skip_bits(gb, 8); //hrd_full[n]
576
        }
577
    }
578

    
579
    if(get_bits1(gb)){
580
        avctx->coded_width = (get_bits(gb, 12)+1)<<1;
581
        avctx->coded_height = (get_bits(gb, 12)+1)<<1;
582
    }
583
    if(v->extended_mv)
584
        v->extended_dmv = get_bits1(gb);
585
    if((v->range_mapy_flag = get_bits1(gb))) {
586
        av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
587
        v->range_mapy = get_bits(gb, 3);
588
    }
589
    if((v->range_mapuv_flag = get_bits1(gb))) {
590
        av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
591
        v->range_mapuv = get_bits(gb, 3);
592
    }
593

    
594
    av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
595
        "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
596
        "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
597
        "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
598
        v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
599
        v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
600

    
601
    return 0;
602
}
603

    
604
int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
605
{
606
    int pqindex, lowquant, status;
607

    
608
    if(v->res_sprite) {
609
        skip_bits(gb, 2); //not yet deciphered
610
    }
611
    if(v->finterpflag) v->interpfrm = get_bits1(gb);
612
    skip_bits(gb, 2); //framecnt unused
613
    v->rangeredfrm = 0;
614
    if (v->rangered) v->rangeredfrm = get_bits1(gb);
615
    v->s.pict_type = get_bits1(gb);
616
    if (v->s.avctx->max_b_frames) {
617
        if (!v->s.pict_type) {
618
            if (get_bits1(gb)) v->s.pict_type = FF_I_TYPE;
619
            else v->s.pict_type = FF_B_TYPE;
620
        } else v->s.pict_type = FF_P_TYPE;
621
    } else v->s.pict_type = v->s.pict_type ? FF_P_TYPE : FF_I_TYPE;
622

    
623
    v->bi_type = 0;
624
    if(v->s.pict_type == FF_B_TYPE) {
625
        v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
626
        v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
627
        if(v->bfraction == 0) {
628
            v->s.pict_type = FF_BI_TYPE;
629
        }
630
    }
631
    if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
632
        skip_bits(gb, 7); // skip buffer fullness
633

    
634
    if(v->parse_only)
635
        return 0;
636

    
637
    /* calculate RND */
638
    if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
639
        v->rnd = 1;
640
    if(v->s.pict_type == FF_P_TYPE)
641
        v->rnd ^= 1;
642

    
643
    /* Quantizer stuff */
644
    pqindex = get_bits(gb, 5);
645
    if(!pqindex) return -1;
646
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
647
        v->pq = ff_vc1_pquant_table[0][pqindex];
648
    else
649
        v->pq = ff_vc1_pquant_table[1][pqindex];
650

    
651
    v->pquantizer = 1;
652
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
653
        v->pquantizer = pqindex < 9;
654
    if (v->quantizer_mode == QUANT_NON_UNIFORM)
655
        v->pquantizer = 0;
656
    v->pqindex = pqindex;
657
    if (pqindex < 9) v->halfpq = get_bits1(gb);
658
    else v->halfpq = 0;
659
    if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
660
        v->pquantizer = get_bits1(gb);
661
    v->dquantfrm = 0;
662
    if (v->extended_mv == 1) v->mvrange = get_unary(gb, 0, 3);
663
    v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
664
    v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
665
    v->range_x = 1 << (v->k_x - 1);
666
    v->range_y = 1 << (v->k_y - 1);
667
    if (v->multires && v->s.pict_type != FF_B_TYPE) v->respic = get_bits(gb, 2);
668

    
669
    if(v->res_x8 && (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)){
670
        v->x8_type = get_bits1(gb);
671
    }else v->x8_type = 0;
672
//av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
673
//        (v->s.pict_type == FF_P_TYPE) ? 'P' : ((v->s.pict_type == FF_I_TYPE) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm);
674

    
675
    if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0;
676

    
677
    switch(v->s.pict_type) {
678
    case FF_P_TYPE:
679
        if (v->pq < 5) v->tt_index = 0;
680
        else if(v->pq < 13) v->tt_index = 1;
681
        else v->tt_index = 2;
682

    
683
        lowquant = (v->pq > 12) ? 0 : 1;
684
        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
685
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
686
        {
687
            int scale, shift, i;
688
            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
689
            v->lumscale = get_bits(gb, 6);
690
            v->lumshift = get_bits(gb, 6);
691
            v->use_ic = 1;
692
            /* fill lookup tables for intensity compensation */
693
            if(!v->lumscale) {
694
                scale = -64;
695
                shift = (255 - v->lumshift * 2) << 6;
696
                if(v->lumshift > 31)
697
                    shift += 128 << 6;
698
            } else {
699
                scale = v->lumscale + 32;
700
                if(v->lumshift > 31)
701
                    shift = (v->lumshift - 64) << 6;
702
                else
703
                    shift = v->lumshift << 6;
704
            }
705
            for(i = 0; i < 256; i++) {
706
                v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
707
                v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
708
            }
709
        }
710
        if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
711
            v->s.quarter_sample = 0;
712
        else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
713
            if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
714
                v->s.quarter_sample = 0;
715
            else
716
                v->s.quarter_sample = 1;
717
        } else
718
            v->s.quarter_sample = 1;
719
        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));
720

    
721
        if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
722
                 v->mv_mode2 == MV_PMODE_MIXED_MV)
723
                || v->mv_mode == MV_PMODE_MIXED_MV)
724
        {
725
            status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
726
            if (status < 0) return -1;
727
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
728
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
729
        } else {
730
            v->mv_type_is_raw = 0;
731
            memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
732
        }
733
        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
734
        if (status < 0) return -1;
735
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
736
               "Imode: %i, Invert: %i\n", status>>1, status&1);
737

    
738
        /* Hopefully this is correct for P frames */
739
        v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
740
        v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
741

    
742
        if (v->dquant)
743
        {
744
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
745
            vop_dquant_decoding(v);
746
        }
747

    
748
        v->ttfrm = 0; //FIXME Is that so ?
749
        if (v->vstransform)
750
        {
751
            v->ttmbf = get_bits1(gb);
752
            if (v->ttmbf)
753
            {
754
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
755
            }
756
        } else {
757
            v->ttmbf = 1;
758
            v->ttfrm = TT_8X8;
759
        }
760
        break;
761
    case FF_B_TYPE:
762
        if (v->pq < 5) v->tt_index = 0;
763
        else if(v->pq < 13) v->tt_index = 1;
764
        else v->tt_index = 2;
765

    
766
        v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
767
        v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
768
        v->s.mspel = v->s.quarter_sample;
769

    
770
        status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
771
        if (status < 0) return -1;
772
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
773
               "Imode: %i, Invert: %i\n", status>>1, status&1);
774
        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
775
        if (status < 0) return -1;
776
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
777
               "Imode: %i, Invert: %i\n", status>>1, status&1);
778

    
779
        v->s.mv_table_index = get_bits(gb, 2);
780
        v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
781

    
782
        if (v->dquant)
783
        {
784
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
785
            vop_dquant_decoding(v);
786
        }
787

    
788
        v->ttfrm = 0;
789
        if (v->vstransform)
790
        {
791
            v->ttmbf = get_bits1(gb);
792
            if (v->ttmbf)
793
            {
794
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
795
            }
796
        } else {
797
            v->ttmbf = 1;
798
            v->ttfrm = TT_8X8;
799
        }
800
        break;
801
    }
802

    
803
    if(!v->x8_type)
804
    {
805
        /* AC Syntax */
806
        v->c_ac_table_index = decode012(gb);
807
        if (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
808
        {
809
            v->y_ac_table_index = decode012(gb);
810
        }
811
        /* DC Syntax */
812
        v->s.dc_table_index = get_bits1(gb);
813
    }
814

    
815
    if(v->s.pict_type == FF_BI_TYPE) {
816
        v->s.pict_type = FF_B_TYPE;
817
        v->bi_type = 1;
818
    }
819
    return 0;
820
}
821

    
822
int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
823
{
824
    int pqindex, lowquant;
825
    int status;
826

    
827
    v->p_frame_skipped = 0;
828

    
829
    if(v->interlace){
830
        v->fcm = decode012(gb);
831
        if(v->fcm){
832
            if(!v->warn_interlaced++)
833
                av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced frames/fields support is not implemented\n");
834
            return -1;
835
        }
836
    }
837
    switch(get_unary(gb, 0, 4)) {
838
    case 0:
839
        v->s.pict_type = FF_P_TYPE;
840
        break;
841
    case 1:
842
        v->s.pict_type = FF_B_TYPE;
843
        break;
844
    case 2:
845
        v->s.pict_type = FF_I_TYPE;
846
        break;
847
    case 3:
848
        v->s.pict_type = FF_BI_TYPE;
849
        break;
850
    case 4:
851
        v->s.pict_type = FF_P_TYPE; // skipped pic
852
        v->p_frame_skipped = 1;
853
        return 0;
854
    }
855
    if(v->tfcntrflag)
856
        skip_bits(gb, 8);
857
    if(v->broadcast) {
858
        if(!v->interlace || v->psf) {
859
            v->rptfrm = get_bits(gb, 2);
860
        } else {
861
            v->tff = get_bits1(gb);
862
            v->rptfrm = get_bits1(gb);
863
        }
864
    }
865
    if(v->panscanflag) {
866
        //...
867
    }
868
    v->rnd = get_bits1(gb);
869
    if(v->interlace)
870
        v->uvsamp = get_bits1(gb);
871
    if(v->finterpflag) v->interpfrm = get_bits1(gb);
872
    if(v->s.pict_type == FF_B_TYPE) {
873
        v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
874
        v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
875
        if(v->bfraction == 0) {
876
            v->s.pict_type = FF_BI_TYPE; /* XXX: should not happen here */
877
        }
878
    }
879
    pqindex = get_bits(gb, 5);
880
    if(!pqindex) return -1;
881
    v->pqindex = pqindex;
882
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
883
        v->pq = ff_vc1_pquant_table[0][pqindex];
884
    else
885
        v->pq = ff_vc1_pquant_table[1][pqindex];
886

    
887
    v->pquantizer = 1;
888
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
889
        v->pquantizer = pqindex < 9;
890
    if (v->quantizer_mode == QUANT_NON_UNIFORM)
891
        v->pquantizer = 0;
892
    v->pqindex = pqindex;
893
    if (pqindex < 9) v->halfpq = get_bits1(gb);
894
    else v->halfpq = 0;
895
    if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
896
        v->pquantizer = get_bits1(gb);
897
    if(v->postprocflag)
898
        v->postproc = get_bits(gb, 2);
899

    
900
    if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0;
901

    
902
    if(v->parse_only)
903
        return 0;
904

    
905
    switch(v->s.pict_type) {
906
    case FF_I_TYPE:
907
    case FF_BI_TYPE:
908
        status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
909
        if (status < 0) return -1;
910
        av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
911
                "Imode: %i, Invert: %i\n", status>>1, status&1);
912
        v->condover = CONDOVER_NONE;
913
        if(v->overlap && v->pq <= 8) {
914
            v->condover = decode012(gb);
915
            if(v->condover == CONDOVER_SELECT) {
916
                status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
917
                if (status < 0) return -1;
918
                av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
919
                        "Imode: %i, Invert: %i\n", status>>1, status&1);
920
            }
921
        }
922
        break;
923
    case FF_P_TYPE:
924
        if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
925
        else v->mvrange = 0;
926
        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
927
        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
928
        v->range_x = 1 << (v->k_x - 1);
929
        v->range_y = 1 << (v->k_y - 1);
930

    
931
        if (v->pq < 5) v->tt_index = 0;
932
        else if(v->pq < 13) v->tt_index = 1;
933
        else v->tt_index = 2;
934

    
935
        lowquant = (v->pq > 12) ? 0 : 1;
936
        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
937
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
938
        {
939
            int scale, shift, i;
940
            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
941
            v->lumscale = get_bits(gb, 6);
942
            v->lumshift = get_bits(gb, 6);
943
            /* fill lookup tables for intensity compensation */
944
            if(!v->lumscale) {
945
                scale = -64;
946
                shift = (255 - v->lumshift * 2) << 6;
947
                if(v->lumshift > 31)
948
                    shift += 128 << 6;
949
            } else {
950
                scale = v->lumscale + 32;
951
                if(v->lumshift > 31)
952
                    shift = (v->lumshift - 64) << 6;
953
                else
954
                    shift = v->lumshift << 6;
955
            }
956
            for(i = 0; i < 256; i++) {
957
                v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
958
                v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
959
            }
960
            v->use_ic = 1;
961
        }
962
        if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
963
            v->s.quarter_sample = 0;
964
        else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
965
            if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
966
                v->s.quarter_sample = 0;
967
            else
968
                v->s.quarter_sample = 1;
969
        } else
970
            v->s.quarter_sample = 1;
971
        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));
972

    
973
        if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
974
                 v->mv_mode2 == MV_PMODE_MIXED_MV)
975
                || v->mv_mode == MV_PMODE_MIXED_MV)
976
        {
977
            status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
978
            if (status < 0) return -1;
979
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
980
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
981
        } else {
982
            v->mv_type_is_raw = 0;
983
            memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
984
        }
985
        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
986
        if (status < 0) return -1;
987
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
988
               "Imode: %i, Invert: %i\n", status>>1, status&1);
989

    
990
        /* Hopefully this is correct for P frames */
991
        v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
992
        v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
993
        if (v->dquant)
994
        {
995
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
996
            vop_dquant_decoding(v);
997
        }
998

    
999
        v->ttfrm = 0; //FIXME Is that so ?
1000
        if (v->vstransform)
1001
        {
1002
            v->ttmbf = get_bits1(gb);
1003
            if (v->ttmbf)
1004
            {
1005
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1006
            }
1007
        } else {
1008
            v->ttmbf = 1;
1009
            v->ttfrm = TT_8X8;
1010
        }
1011
        break;
1012
    case FF_B_TYPE:
1013
        if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
1014
        else v->mvrange = 0;
1015
        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1016
        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1017
        v->range_x = 1 << (v->k_x - 1);
1018
        v->range_y = 1 << (v->k_y - 1);
1019

    
1020
        if (v->pq < 5) v->tt_index = 0;
1021
        else if(v->pq < 13) v->tt_index = 1;
1022
        else v->tt_index = 2;
1023

    
1024
        v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
1025
        v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
1026
        v->s.mspel = v->s.quarter_sample;
1027

    
1028
        status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1029
        if (status < 0) return -1;
1030
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1031
               "Imode: %i, Invert: %i\n", status>>1, status&1);
1032
        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1033
        if (status < 0) return -1;
1034
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1035
               "Imode: %i, Invert: %i\n", status>>1, status&1);
1036

    
1037
        v->s.mv_table_index = get_bits(gb, 2);
1038
        v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
1039

    
1040
        if (v->dquant)
1041
        {
1042
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1043
            vop_dquant_decoding(v);
1044
        }
1045

    
1046
        v->ttfrm = 0;
1047
        if (v->vstransform)
1048
        {
1049
            v->ttmbf = get_bits1(gb);
1050
            if (v->ttmbf)
1051
            {
1052
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1053
            }
1054
        } else {
1055
            v->ttmbf = 1;
1056
            v->ttfrm = TT_8X8;
1057
        }
1058
        break;
1059
    }
1060

    
1061
    /* AC Syntax */
1062
    v->c_ac_table_index = decode012(gb);
1063
    if (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
1064
    {
1065
        v->y_ac_table_index = decode012(gb);
1066
    }
1067
    /* DC Syntax */
1068
    v->s.dc_table_index = get_bits1(gb);
1069
    if ((v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) && v->dquant) {
1070
        av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1071
        vop_dquant_decoding(v);
1072
    }
1073

    
1074
    v->bi_type = 0;
1075
    if(v->s.pict_type == FF_BI_TYPE) {
1076
        v->s.pict_type = FF_B_TYPE;
1077
        v->bi_type = 1;
1078
    }
1079
    return 0;
1080
}