int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)

{

    av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));

    v->profile = get_bits(gb, 2);

    if (v->profile == PROFILE_COMPLEX)

    {

        av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");

    }



    if (v->profile == PROFILE_ADVANCED)

    {

        v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;

        v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;

        return decode_sequence_header_adv(v, gb);

    }

    else

    {

        v->zz_8x4 = wmv2_scantableA;

        v->zz_4x8 = wmv2_scantableB;

        v->res_y411   = get_bits1(gb);

        v->res_sprite = get_bits1(gb);

        if (v->res_y411)

        {

            av_log(avctx, AV_LOG_ERROR,

                   "Old interlaced mode is not supported\n");

            return -1;

        }

        if (v->res_sprite) {

            av_log(avctx, AV_LOG_ERROR, "WMVP is not fully supported\n");

        }

    }



    // (fps-2)/4 (->30)

    v->frmrtq_postproc = get_bits(gb, 3); //common

    // (bitrate-32kbps)/64kbps

    v->bitrtq_postproc = get_bits(gb, 5); //common

    v->s.loop_filter = get_bits1(gb); //common

    if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)

    {

        av_log(avctx, AV_LOG_ERROR,

               "LOOPFILTER shall not be enabled in Simple Profile\n");

    }

    if(v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)

        v->s.loop_filter = 0;



    v->res_x8 = get_bits1(gb); //reserved

    v->multires = get_bits1(gb);

    v->res_fasttx = get_bits1(gb);

    if (!v->res_fasttx)

    {

        v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct;

        v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;

        v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;

        v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;

        v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add;

        v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;

        v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;

        v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;

    }



    v->fastuvmc =  get_bits1(gb); //common

    if (!v->profile && !v->fastuvmc)

    {

        av_log(avctx, AV_LOG_ERROR,

               "FASTUVMC unavailable in Simple Profile\n");

        return -1;

    }

    v->extended_mv =  get_bits1(gb); //common

    if (!v->profile && v->extended_mv)

    {

        av_log(avctx, AV_LOG_ERROR,

               "Extended MVs unavailable in Simple Profile\n");

        return -1;

    }

    v->dquant =  get_bits(gb, 2); //common

    v->vstransform =  get_bits1(gb); //common



    v->res_transtab = get_bits1(gb);

    if (v->res_transtab)

    {

        av_log(avctx, AV_LOG_ERROR,

               "1 for reserved RES_TRANSTAB is forbidden\n");

        return -1;

    }



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



    v->s.resync_marker = get_bits1(gb);

    v->rangered = get_bits1(gb);

    if (v->rangered && v->profile == PROFILE_SIMPLE)

    {

        av_log(avctx, AV_LOG_INFO,

               "RANGERED should be set to 0 in Simple Profile\n");

    }



    v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common

    v->quantizer_mode = get_bits(gb, 2); //common



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



    if (v->res_sprite) {

        v->s.avctx->width  = v->s.avctx->coded_width  = get_bits(gb, 11);

        v->s.avctx->height = v->s.avctx->coded_height = get_bits(gb, 11);

        skip_bits(gb, 5); //frame rate

        v->res_x8 = get_bits1(gb);

        if (get_bits1(gb)) { // something to do with DC VLC selection

            av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");

            return -1;

        }

        skip_bits(gb, 3); //slice code

        v->res_rtm_flag = 0;

    } else {

        v->res_rtm_flag = get_bits1(gb); //reserved

    }

    if (!v->res_rtm_flag)

    {

//            av_log(avctx, AV_LOG_ERROR,

//                   "0 for reserved RES_RTM_FLAG is forbidden\n");

        av_log(avctx, AV_LOG_ERROR,

               "Old WMV3 version detected, some frames may be decoded incorrectly\n");

        //return -1;

    }

    //TODO: figure out what they mean (always 0x402F)

    if(!v->res_fasttx) skip_bits(gb, 16);

    av_log(avctx, AV_LOG_DEBUG,

               "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"

               "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"

               "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"

               "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",

               v->profile, v->frmrtq_postproc, v->bitrtq_postproc,

               v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,

               v->rangered, v->vstransform, v->overlap, v->s.resync_marker,

               v->dquant, v->quantizer_mode, avctx->max_b_frames

               );

    return 0;

}

int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)

{

    av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));

    v->profile = get_bits(gb, 2);

    if (v->profile == PROFILE_COMPLEX)

    {

        av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");

    }



    if (v->profile == PROFILE_ADVANCED)

    {

        v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;

        v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;

        return decode_sequence_header_adv(v, gb);

    }

    else

    {

        v->zz_8x4 = wmv2_scantableA;

        v->zz_4x8 = wmv2_scantableB;

        v->res_y411   = get_bits1(gb);

        v->res_sprite = get_bits1(gb);

        if (v->res_y411)

        {

            av_log(avctx, AV_LOG_ERROR,

                   "Old interlaced mode is not supported\n");

            return -1;

        }

        if (v->res_sprite) {

            av_log(avctx, AV_LOG_ERROR, "WMVP is not fully supported\n");

        }

    }



    

    v->frmrtq_postproc = get_bits(gb, 3); 

    

    v->bitrtq_postproc = get_bits(gb, 5); 

    v->s.loop_filter = get_bits1(gb); 

    if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)

    {

        av_log(avctx, AV_LOG_ERROR,

               "LOOPFILTER shall not be enabled in Simple Profile\n");

    }

    if(v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)

        v->s.loop_filter = 0;



    v->res_x8 = get_bits1(gb); 

    v->multires = get_bits1(gb);

    v->res_fasttx = get_bits1(gb);

    if (!v->res_fasttx)

    {

        v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct;

        v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;

        v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;

        v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;

        v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add;

        v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;

        v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;

        v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;

    }



    v->fastuvmc =  get_bits1(gb); 

    if (!v->profile && !v->fastuvmc)

    {

        av_log(avctx, AV_LOG_ERROR,

               "FASTUVMC unavailable in Simple Profile\n");

        return -1;

    }

    v->extended_mv =  get_bits1(gb); 

    if (!v->profile && v->extended_mv)

    {

        av_log(avctx, AV_LOG_ERROR,

               "Extended MVs unavailable in Simple Profile\n");

        return -1;

    }

    v->dquant =  get_bits(gb, 2); 

    v->vstransform =  get_bits1(gb); 



    v->res_transtab = get_bits1(gb);

    if (v->res_transtab)

    {

        av_log(avctx, AV_LOG_ERROR,

               "1 for reserved RES_TRANSTAB is forbidden\n");

        return -1;

    }



    v->overlap = get_bits1(gb); 



    v->s.resync_marker = get_bits1(gb);

    v->rangered = get_bits1(gb);

    if (v->rangered && v->profile == PROFILE_SIMPLE)

    {

        av_log(avctx, AV_LOG_INFO,

               "RANGERED should be set to 0 in Simple Profile\n");

    }



    v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); 

    v->quantizer_mode = get_bits(gb, 2); 



    v->finterpflag = get_bits1(gb); 



    if (v->res_sprite) {

        v->s.avctx->width  = v->s.avctx->coded_width  = get_bits(gb, 11);

        v->s.avctx->height = v->s.avctx->coded_height = get_bits(gb, 11);

        skip_bits(gb, 5); 

        v->res_x8 = get_bits1(gb);

        if (get_bits1(gb)) { 

            av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");

            return -1;

        }

        skip_bits(gb, 3); 

        v->res_rtm_flag = 0;

    } else {

        v->res_rtm_flag = get_bits1(gb); 

    }

    if (!v->res_rtm_flag)

    {





        av_log(avctx, AV_LOG_ERROR,

               "Old WMV3 version detected, some frames may be decoded incorrectly\n");

        

    }

    

    if(!v->res_fasttx) skip_bits(gb, 16);

    av_log(avctx, AV_LOG_DEBUG,

               "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"

               "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"

               "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"

               "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",

               v->profile, v->frmrtq_postproc, v->bitrtq_postproc,

               v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,

               v->rangered, v->vstransform, v->overlap, v->s.resync_marker,

               v->dquant, v->quantizer_mode, avctx->max_b_frames

               );

    return 0;

}

int FUNC_0(AVCodecContext *VAR_0, VC1Context *VAR_1, GetBitContext *VAR_2)

{

    av_log(VAR_0, AV_LOG_DEBUG, "Header: %0X\n", show_bits(VAR_2, 32));

    VAR_1->profile = get_bits(VAR_2, 2);

    if (VAR_1->profile == PROFILE_COMPLEX)

    {

        av_log(VAR_0, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");

    }



    if (VAR_1->profile == PROFILE_ADVANCED)

    {

        VAR_1->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;

        VAR_1->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;

        return decode_sequence_header_adv(VAR_1, VAR_2);

    }

    else

    {

        VAR_1->zz_8x4 = wmv2_scantableA;

        VAR_1->zz_4x8 = wmv2_scantableB;

        VAR_1->res_y411   = get_bits1(VAR_2);

        VAR_1->res_sprite = get_bits1(VAR_2);

        if (VAR_1->res_y411)

        {

            av_log(VAR_0, AV_LOG_ERROR,

                   "Old interlaced mode is not supported\n");

            return -1;

        }

        if (VAR_1->res_sprite) {

            av_log(VAR_0, AV_LOG_ERROR, "WMVP is not fully supported\n");

        }

    }



    

    VAR_1->frmrtq_postproc = get_bits(VAR_2, 3); 

    

    VAR_1->bitrtq_postproc = get_bits(VAR_2, 5); 

    VAR_1->s.loop_filter = get_bits1(VAR_2); 

    if(VAR_1->s.loop_filter == 1 && VAR_1->profile == PROFILE_SIMPLE)

    {

        av_log(VAR_0, AV_LOG_ERROR,

               "LOOPFILTER shall not be enabled in Simple Profile\n");

    }

    if(VAR_1->s.VAR_0->skip_loop_filter >= AVDISCARD_ALL)

        VAR_1->s.loop_filter = 0;



    VAR_1->res_x8 = get_bits1(VAR_2); 

    VAR_1->multires = get_bits1(VAR_2);

    VAR_1->res_fasttx = get_bits1(VAR_2);

    if (!VAR_1->res_fasttx)

    {

        VAR_1->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct;

        VAR_1->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;

        VAR_1->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;

        VAR_1->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;

        VAR_1->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add;

        VAR_1->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;

        VAR_1->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;

        VAR_1->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;

    }



    VAR_1->fastuvmc =  get_bits1(VAR_2); 

    if (!VAR_1->profile && !VAR_1->fastuvmc)

    {

        av_log(VAR_0, AV_LOG_ERROR,

               "FASTUVMC unavailable in Simple Profile\n");

        return -1;

    }

    VAR_1->extended_mv =  get_bits1(VAR_2); 

    if (!VAR_1->profile && VAR_1->extended_mv)

    {

        av_log(VAR_0, AV_LOG_ERROR,

               "Extended MVs unavailable in Simple Profile\n");

        return -1;

    }

    VAR_1->dquant =  get_bits(VAR_2, 2); 

    VAR_1->vstransform =  get_bits1(VAR_2); 



    VAR_1->res_transtab = get_bits1(VAR_2);

    if (VAR_1->res_transtab)

    {

        av_log(VAR_0, AV_LOG_ERROR,

               "1 for reserved RES_TRANSTAB is forbidden\n");

        return -1;

    }



    VAR_1->overlap = get_bits1(VAR_2); 



    VAR_1->s.resync_marker = get_bits1(VAR_2);

    VAR_1->rangered = get_bits1(VAR_2);

    if (VAR_1->rangered && VAR_1->profile == PROFILE_SIMPLE)

    {

        av_log(VAR_0, AV_LOG_INFO,

               "RANGERED should be set to 0 in Simple Profile\n");

    }



    VAR_1->s.max_b_frames = VAR_0->max_b_frames = get_bits(VAR_2, 3); 

    VAR_1->quantizer_mode = get_bits(VAR_2, 2); 



    VAR_1->finterpflag = get_bits1(VAR_2); 



    if (VAR_1->res_sprite) {

        VAR_1->s.VAR_0->width  = VAR_1->s.VAR_0->coded_width  = get_bits(VAR_2, 11);

        VAR_1->s.VAR_0->height = VAR_1->s.VAR_0->coded_height = get_bits(VAR_2, 11);

        skip_bits(VAR_2, 5); 

        VAR_1->res_x8 = get_bits1(VAR_2);

        if (get_bits1(VAR_2)) { 

            av_log(VAR_0, AV_LOG_ERROR, "Unsupported sprite feature\n");

            return -1;

        }

        skip_bits(VAR_2, 3); 

        VAR_1->res_rtm_flag = 0;

    } else {

        VAR_1->res_rtm_flag = get_bits1(VAR_2); 

    }

    if (!VAR_1->res_rtm_flag)

    {





        av_log(VAR_0, AV_LOG_ERROR,

               "Old WMV3 version detected, some frames may be decoded incorrectly\n");

        

    }

    

    if(!VAR_1->res_fasttx) skip_bits(VAR_2, 16);

    av_log(VAR_0, AV_LOG_DEBUG,

               "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"

               "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"

               "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"

               "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",

               VAR_1->profile, VAR_1->frmrtq_postproc, VAR_1->bitrtq_postproc,

               VAR_1->s.loop_filter, VAR_1->multires, VAR_1->fastuvmc, VAR_1->extended_mv,

               VAR_1->rangered, VAR_1->vstransform, VAR_1->overlap, VAR_1->s.resync_marker,

               VAR_1->dquant, VAR_1->quantizer_mode, VAR_0->max_b_frames

               );

    return 0;

}

int FUNC_0(AVCodecContext *VAR_0, VC1Context *VAR_1, GetBitContext *VAR_2)
{ av_log(VAR_0, AV_LOG_DEBUG, "Header: %0X\n", show_bits(VAR_2, 32)); VAR_1->profile = get_bits(VAR_2, 2); if (VAR_1->profile == PROFILE_COMPLEX)
{ av_log(VAR_0, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n"); } if (VAR_1->profile == PROFILE_ADVANCED)
{ VAR_1->zz_8x4 = ff_vc1_adv_progressive_8x4_zz; VAR_1->zz_4x8 = ff_vc1_adv_progressive_4x8_zz; return decode_sequence_header_adv(VAR_1, VAR_2); } else
{ VAR_1->zz_8x4 = wmv2_scantableA; VAR_1->zz_4x8 = wmv2_scantableB; VAR_1->res_y411   = get_bits1(VAR_2); VAR_1->res_sprite = get_bits1(VAR_2); if (VAR_1->res_y411)
{ av_log(VAR_0, AV_LOG_ERROR,
"Old interlaced mode is not supported\n"); return -1; } if (VAR_1->res_sprite) { av_log(VAR_0, AV_LOG_ERROR, "WMVP is not fully supported\n"); } } VAR_1->frmrtq_postproc = get_bits(VAR_2, 3); VAR_1->bitrtq_postproc = get_bits(VAR_2, 5); VAR_1->s.loop_filter = get_bits1(VAR_2); if(VAR_1->s.loop_filter == 1 && VAR_1->profile == PROFILE_SIMPLE)
{ av_log(VAR_0, AV_LOG_ERROR,
"LOOPFILTER shall not be enabled in Simple Profile\n"); } if(VAR_1->s.VAR_0->skip_loop_filter >= AVDISCARD_ALL)
VAR_1->s.loop_filter = 0; VAR_1->res_x8 = get_bits1(VAR_2); VAR_1->multires = get_bits1(VAR_2); VAR_1->res_fasttx = get_bits1(VAR_2); if (!VAR_1->res_fasttx)
{ VAR_1->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct; VAR_1->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add; VAR_1->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add; VAR_1->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add; VAR_1->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add; VAR_1->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add; VAR_1->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add; VAR_1->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add; } VAR_1->fastuvmc =  get_bits1(VAR_2); if (!VAR_1->profile && !VAR_1->fastuvmc)
{ av_log(VAR_0, AV_LOG_ERROR,
"FASTUVMC unavailable in Simple Profile\n"); return -1; } VAR_1->extended_mv =  get_bits1(VAR_2); if (!VAR_1->profile && VAR_1->extended_mv)
{ av_log(VAR_0, AV_LOG_ERROR,
"Extended MVs unavailable in Simple Profile\n"); return -1; } VAR_1->dquant =  get_bits(VAR_2, 2); VAR_1->vstransform =  get_bits1(VAR_2); VAR_1->res_transtab = get_bits1(VAR_2); if (VAR_1->res_transtab)
{ av_log(VAR_0, AV_LOG_ERROR,
"1 for reserved RES_TRANSTAB is forbidden\n"); return -1; } VAR_1->overlap = get_bits1(VAR_2); VAR_1->s.resync_marker = get_bits1(VAR_2); VAR_1->rangered = get_bits1(VAR_2); if (VAR_1->rangered && VAR_1->profile == PROFILE_SIMPLE)
{ av_log(VAR_0, AV_LOG_INFO,
"RANGERED should be set to 0 in Simple Profile\n"); } VAR_1->s.max_b_frames = VAR_0->max_b_frames = get_bits(VAR_2, 3); VAR_1->quantizer_mode = get_bits(VAR_2, 2); VAR_1->finterpflag = get_bits1(VAR_2); if (VAR_1->res_sprite) { VAR_1->s.VAR_0->width  = VAR_1->s.VAR_0->coded_width  = get_bits(VAR_2, 11); VAR_1->s.VAR_0->height = VAR_1->s.VAR_0->coded_height = get_bits(VAR_2, 11); skip_bits(VAR_2, 5); VAR_1->res_x8 = get_bits1(VAR_2); if (get_bits1(VAR_2)) { av_log(VAR_0, AV_LOG_ERROR, "Unsupported sprite feature\n"); return -1; } skip_bits(VAR_2, 3); VAR_1->res_rtm_flag = 0; } else { VAR_1->res_rtm_flag = get_bits1(VAR_2); } if (!VAR_1->res_rtm_flag)
{ av_log(VAR_0, AV_LOG_ERROR,
"Old WMV3 version detected, some frames may be decoded incorrectly\n"); } if(!VAR_1->res_fasttx) skip_bits(VAR_2, 16); av_log(VAR_0, AV_LOG_DEBUG,
"Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
"LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
"Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
"DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
VAR_1->profile, VAR_1->frmrtq_postproc, VAR_1->bitrtq_postproc,
VAR_1->s.loop_filter, VAR_1->multires, VAR_1->fastuvmc, VAR_1->extended_mv,
VAR_1->rangered, VAR_1->vstransform, VAR_1->overlap, VAR_1->s.resync_marker,
VAR_1->dquant, VAR_1->quantizer_mode, VAR_0->max_b_frames
); return 0; }