int ff_h263_decode_picture_header(MpegEncContext *s)

{

    int format, width, height, i;

    uint32_t startcode;



    align_get_bits(&s->gb);



    if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_number == 0) {

         av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");

    }



    startcode= get_bits(&s->gb, 22-8);



    for(i= get_bits_left(&s->gb); i>24; i-=8) {

        startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;



        if(startcode == 0x20)

            break;

    }



    if (startcode != 0x20) {

        av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");

        return -1;

    }

    /* temporal reference */

    i = get_bits(&s->gb, 8); /* picture timestamp */

    if( (s->picture_number&~0xFF)+i < s->picture_number)

        i+= 256;

    s->picture_number= (s->picture_number&~0xFF) + i;



    /* PTYPE starts here */

    if (get_bits1(&s->gb) != 1) {

        /* marker */

        av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");

        return -1;

    }

    if (get_bits1(&s->gb) != 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");

        return -1;      /* h263 id */

    }

    skip_bits1(&s->gb);         /* split screen off */

    skip_bits1(&s->gb);         /* camera  off */

    skip_bits1(&s->gb);         /* freeze picture release off */



    format = get_bits(&s->gb, 3);

    /*

        0    forbidden

        1    sub-QCIF

        10   QCIF

        7       extended PTYPE (PLUSPTYPE)

    */



    if (format != 7 && format != 6) {

        s->h263_plus = 0;

        /* H.263v1 */

        width = ff_h263_format[format][0];

        height = ff_h263_format[format][1];

        if (!width)

            return -1;



        s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);



        s->h263_long_vectors = get_bits1(&s->gb);



        if (get_bits1(&s->gb) != 0) {

            av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n");

            return -1; /* SAC: off */

        }

        s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */

        s->unrestricted_mv = s->h263_long_vectors || s->obmc;



        s->pb_frame = get_bits1(&s->gb);

        s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);

        skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */



        s->width = width;

        s->height = height;

        s->avctx->sample_aspect_ratio= (AVRational){12,11};

        s->avctx->framerate = (AVRational){ 30000, 1001 };

    } else {

        int ufep;



        /* H.263v2 */

        s->h263_plus = 1;

        ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */



        /* ufep other than 0 and 1 are reserved */

        if (ufep == 1) {

            /* OPPTYPE */

            format = get_bits(&s->gb, 3);

            av_dlog(s->avctx, "ufep=1, format: %d\n", format);

            s->custom_pcf= get_bits1(&s->gb);

            s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */

            if (get_bits1(&s->gb) != 0) {

                av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");

            }

            s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */

            s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */

            s->loop_filter= get_bits1(&s->gb);

            s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;

            if(s->avctx->lowres)

                s->loop_filter = 0;



            s->h263_slice_structured= get_bits1(&s->gb);

            if (get_bits1(&s->gb) != 0) {

                av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");

            }

            if (get_bits1(&s->gb) != 0) {

                av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");

            }

            s->alt_inter_vlc= get_bits1(&s->gb);

            s->modified_quant= get_bits1(&s->gb);

            if(s->modified_quant)

                s->chroma_qscale_table= ff_h263_chroma_qscale_table;



            skip_bits(&s->gb, 1); /* Prevent start code emulation */



            skip_bits(&s->gb, 3); /* Reserved */

        } else if (ufep != 0) {

            av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);

            return -1;

        }



        /* MPPTYPE */

        s->pict_type = get_bits(&s->gb, 3);

        switch(s->pict_type){

        case 0: s->pict_type= AV_PICTURE_TYPE_I;break;

        case 1: s->pict_type= AV_PICTURE_TYPE_P;break;

        case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;

        case 3: s->pict_type= AV_PICTURE_TYPE_B;break;

        case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO

        default:

            return -1;

        }

        skip_bits(&s->gb, 2);

        s->no_rounding = get_bits1(&s->gb);

        skip_bits(&s->gb, 4);



        /* Get the picture dimensions */

        if (ufep) {

            if (format == 6) {

                /* Custom Picture Format (CPFMT) */

                s->aspect_ratio_info = get_bits(&s->gb, 4);

                av_dlog(s->avctx, "aspect: %d\n", s->aspect_ratio_info);

                /* aspect ratios:

                0 - forbidden

                1 - 1:1

                2 - 12:11 (CIF 4:3)

                3 - 10:11 (525-type 4:3)

                4 - 16:11 (CIF 16:9)

                5 - 40:33 (525-type 16:9)

                6-14 - reserved

                */

                width = (get_bits(&s->gb, 9) + 1) * 4;

                skip_bits1(&s->gb);

                height = get_bits(&s->gb, 9) * 4;

                av_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);

                if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {

                    /* aspected dimensions */

                    s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);

                    s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);

                }else{

                    s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info];

                }

            } else {

                width = ff_h263_format[format][0];

                height = ff_h263_format[format][1];

                s->avctx->sample_aspect_ratio= (AVRational){12,11};

            }

            s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;

            if ((width == 0) || (height == 0))

                return -1;

            s->width = width;

            s->height = height;



            if(s->custom_pcf){

                int gcd;

                s->avctx->framerate.num  = 1800000;

                s->avctx->framerate.den  = 1000 + get_bits1(&s->gb);

                s->avctx->framerate.den *= get_bits(&s->gb, 7);

                if(s->avctx->framerate.den == 0){

                    av_log(s, AV_LOG_ERROR, "zero framerate\n");

                    return -1;

                }

                gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num);

                s->avctx->framerate.den /= gcd;

                s->avctx->framerate.num /= gcd;

            }else{

                s->avctx->framerate = (AVRational){ 30000, 1001 };

            }

        }



        if(s->custom_pcf){

            skip_bits(&s->gb, 2); //extended Temporal reference

        }



        if (ufep) {

            if (s->umvplus) {

                if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */

                    skip_bits1(&s->gb);

            }

            if(s->h263_slice_structured){

                if (get_bits1(&s->gb) != 0) {

                    av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");

                }

                if (get_bits1(&s->gb) != 0) {

                    av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");

                }

            }

        }



        s->qscale = get_bits(&s->gb, 5);

    }



    if (s->width == 0 || s->height == 0) {

        av_log(s->avctx, AV_LOG_ERROR, "dimensions 0\n");

        return -1;

    }

    s->mb_width = (s->width  + 15) / 16;

    s->mb_height = (s->height  + 15) / 16;

    s->mb_num = s->mb_width * s->mb_height;



    if (s->pb_frame) {

        skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */

        if (s->custom_pcf)

            skip_bits(&s->gb, 2); //extended Temporal reference

        skip_bits(&s->gb, 2); /* Quantization information for B-pictures */

    }



    if (s->pict_type!=AV_PICTURE_TYPE_B) {

        s->time            = s->picture_number;

        s->pp_time         = s->time - s->last_non_b_time;

        s->last_non_b_time = s->time;

    }else{

        s->time    = s->picture_number;

        s->pb_time = s->pp_time - (s->last_non_b_time - s->time);

        if (s->pp_time <=s->pb_time ||

            s->pp_time <= s->pp_time - s->pb_time ||

            s->pp_time <= 0){

            s->pp_time = 2;

            s->pb_time = 1;

        }

        ff_mpeg4_init_direct_mv(s);

    }



    /* PEI */

    if (skip_1stop_8data_bits(&s->gb) < 0)

        return AVERROR_INVALIDDATA;



    if(s->h263_slice_structured){

        if (get_bits1(&s->gb) != 1) {

            av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n");

            return -1;

        }



        ff_h263_decode_mba(s);



        if (get_bits1(&s->gb) != 1) {

            av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n");

            return -1;

        }

    }

    s->f_code = 1;



    if(s->h263_aic){

         s->y_dc_scale_table=

         s->c_dc_scale_table= ff_aic_dc_scale_table;

    }else{

        s->y_dc_scale_table=

        s->c_dc_scale_table= ff_mpeg1_dc_scale_table;

    }



        ff_h263_show_pict_info(s);

    if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){

        int i,j;

        for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));

        av_log(s->avctx, AV_LOG_DEBUG, "\n");

        for(i=0; i<13; i++){

            for(j=0; j<3; j++){

                int v= get_bits(&s->gb, 8);

                v |= get_sbits(&s->gb, 8)<<8;

                av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);

            }

            av_log(s->avctx, AV_LOG_DEBUG, "\n");

        }

        for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));

    }



    return 0;

}

int ff_h263_decode_picture_header(MpegEncContext *s)

{

    int format, width, height, i;

    uint32_t startcode;



    align_get_bits(&s->gb);



    if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_number == 0) {

         av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");

    }



    startcode= get_bits(&s->gb, 22-8);



    for(i= get_bits_left(&s->gb); i>24; i-=8) {

        startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;



        if(startcode == 0x20)

            break;

    }



    if (startcode != 0x20) {

        av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");

        return -1;

    }

    

    i = get_bits(&s->gb, 8); 

    if( (s->picture_number&~0xFF)+i < s->picture_number)

        i+= 256;

    s->picture_number= (s->picture_number&~0xFF) + i;



    

    if (get_bits1(&s->gb) != 1) {

        

        av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");

        return -1;

    }

    if (get_bits1(&s->gb) != 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");

        return -1;      

    }

    skip_bits1(&s->gb);         

    skip_bits1(&s->gb);         

    skip_bits1(&s->gb);         



    format = get_bits(&s->gb, 3);

    













    if (format != 7 && format != 6) {

        s->h263_plus = 0;

        

        width = ff_h263_format[format][0];

        height = ff_h263_format[format][1];

        if (!width)

            return -1;



        s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);



        s->h263_long_vectors = get_bits1(&s->gb);



        if (get_bits1(&s->gb) != 0) {

            av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n");

            return -1; 

        }

        s->obmc= get_bits1(&s->gb); 

        s->unrestricted_mv = s->h263_long_vectors || s->obmc;



        s->pb_frame = get_bits1(&s->gb);

        s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);

        skip_bits1(&s->gb); 



        s->width = width;

        s->height = height;

        s->avctx->sample_aspect_ratio= (AVRational){12,11};

        s->avctx->framerate = (AVRational){ 30000, 1001 };

    } else {

        int ufep;



        

        s->h263_plus = 1;

        ufep = get_bits(&s->gb, 3); 



        

        if (ufep == 1) {

            

            format = get_bits(&s->gb, 3);

            av_dlog(s->avctx, "ufep=1, format: %d\n", format);

            s->custom_pcf= get_bits1(&s->gb);

            s->umvplus = get_bits1(&s->gb); 

            if (get_bits1(&s->gb) != 0) {

                av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");

            }

            s->obmc= get_bits1(&s->gb); 

            s->h263_aic = get_bits1(&s->gb); 

            s->loop_filter= get_bits1(&s->gb);

            s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;

            if(s->avctx->lowres)

                s->loop_filter = 0;



            s->h263_slice_structured= get_bits1(&s->gb);

            if (get_bits1(&s->gb) != 0) {

                av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");

            }

            if (get_bits1(&s->gb) != 0) {

                av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");

            }

            s->alt_inter_vlc= get_bits1(&s->gb);

            s->modified_quant= get_bits1(&s->gb);

            if(s->modified_quant)

                s->chroma_qscale_table= ff_h263_chroma_qscale_table;



            skip_bits(&s->gb, 1); 



            skip_bits(&s->gb, 3); 

        } else if (ufep != 0) {

            av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);

            return -1;

        }



        

        s->pict_type = get_bits(&s->gb, 3);

        switch(s->pict_type){

        case 0: s->pict_type= AV_PICTURE_TYPE_I;break;

        case 1: s->pict_type= AV_PICTURE_TYPE_P;break;

        case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;

        case 3: s->pict_type= AV_PICTURE_TYPE_B;break;

        case 7: s->pict_type= AV_PICTURE_TYPE_I;break; 

        default:

            return -1;

        }

        skip_bits(&s->gb, 2);

        s->no_rounding = get_bits1(&s->gb);

        skip_bits(&s->gb, 4);



        

        if (ufep) {

            if (format == 6) {

                

                s->aspect_ratio_info = get_bits(&s->gb, 4);

                av_dlog(s->avctx, "aspect: %d\n", s->aspect_ratio_info);

                

















                width = (get_bits(&s->gb, 9) + 1) * 4;

                skip_bits1(&s->gb);

                height = get_bits(&s->gb, 9) * 4;

                av_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);

                if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {

                    

                    s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);

                    s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);

                }else{

                    s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info];

                }

            } else {

                width = ff_h263_format[format][0];

                height = ff_h263_format[format][1];

                s->avctx->sample_aspect_ratio= (AVRational){12,11};

            }

            s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;

            if ((width == 0) || (height == 0))

                return -1;

            s->width = width;

            s->height = height;



            if(s->custom_pcf){

                int gcd;

                s->avctx->framerate.num  = 1800000;

                s->avctx->framerate.den  = 1000 + get_bits1(&s->gb);

                s->avctx->framerate.den *= get_bits(&s->gb, 7);

                if(s->avctx->framerate.den == 0){

                    av_log(s, AV_LOG_ERROR, "zero framerate\n");

                    return -1;

                }

                gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num);

                s->avctx->framerate.den /= gcd;

                s->avctx->framerate.num /= gcd;

            }else{

                s->avctx->framerate = (AVRational){ 30000, 1001 };

            }

        }



        if(s->custom_pcf){

            skip_bits(&s->gb, 2); 

        }



        if (ufep) {

            if (s->umvplus) {

                if(get_bits1(&s->gb)==0) 

                    skip_bits1(&s->gb);

            }

            if(s->h263_slice_structured){

                if (get_bits1(&s->gb) != 0) {

                    av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");

                }

                if (get_bits1(&s->gb) != 0) {

                    av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");

                }

            }

        }



        s->qscale = get_bits(&s->gb, 5);

    }



    if (s->width == 0 || s->height == 0) {

        av_log(s->avctx, AV_LOG_ERROR, "dimensions 0\n");

        return -1;

    }

    s->mb_width = (s->width  + 15) / 16;

    s->mb_height = (s->height  + 15) / 16;

    s->mb_num = s->mb_width * s->mb_height;



    if (s->pb_frame) {

        skip_bits(&s->gb, 3); 

        if (s->custom_pcf)

            skip_bits(&s->gb, 2); 

        skip_bits(&s->gb, 2); 

    }



    if (s->pict_type!=AV_PICTURE_TYPE_B) {

        s->time            = s->picture_number;

        s->pp_time         = s->time - s->last_non_b_time;

        s->last_non_b_time = s->time;

    }else{

        s->time    = s->picture_number;

        s->pb_time = s->pp_time - (s->last_non_b_time - s->time);

        if (s->pp_time <=s->pb_time ||

            s->pp_time <= s->pp_time - s->pb_time ||

            s->pp_time <= 0){

            s->pp_time = 2;

            s->pb_time = 1;

        }

        ff_mpeg4_init_direct_mv(s);

    }



    

    if (skip_1stop_8data_bits(&s->gb) < 0)

        return AVERROR_INVALIDDATA;



    if(s->h263_slice_structured){

        if (get_bits1(&s->gb) != 1) {

            av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n");

            return -1;

        }



        ff_h263_decode_mba(s);



        if (get_bits1(&s->gb) != 1) {

            av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n");

            return -1;

        }

    }

    s->f_code = 1;



    if(s->h263_aic){

         s->y_dc_scale_table=

         s->c_dc_scale_table= ff_aic_dc_scale_table;

    }else{

        s->y_dc_scale_table=

        s->c_dc_scale_table= ff_mpeg1_dc_scale_table;

    }



        ff_h263_show_pict_info(s);

    if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){

        int i,j;

        for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));

        av_log(s->avctx, AV_LOG_DEBUG, "\n");

        for(i=0; i<13; i++){

            for(j=0; j<3; j++){

                int v= get_bits(&s->gb, 8);

                v |= get_sbits(&s->gb, 8)<<8;

                av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);

            }

            av_log(s->avctx, AV_LOG_DEBUG, "\n");

        }

        for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));

    }



    return 0;

}

int FUNC_0(MpegEncContext *VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_7;

    uint32_t startcode;



    align_get_bits(&VAR_0->gb);



    if (show_bits(&VAR_0->gb, 2) == 2 && VAR_0->avctx->frame_number == 0) {

         av_log(VAR_0->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");

    }



    startcode= get_bits(&VAR_0->gb, 22-8);



    for(VAR_7= get_bits_left(&VAR_0->gb); VAR_7>24; VAR_7-=8) {

        startcode = ((startcode << 8) | get_bits(&VAR_0->gb, 8)) & 0x003FFFFF;



        if(startcode == 0x20)

            break;

    }



    if (startcode != 0x20) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad picture start code\n");

        return -1;

    }

    

    VAR_7 = get_bits(&VAR_0->gb, 8); 

    if( (VAR_0->picture_number&~0xFF)+VAR_7 < VAR_0->picture_number)

        VAR_7+= 256;

    VAR_0->picture_number= (VAR_0->picture_number&~0xFF) + VAR_7;



    

    if (get_bits1(&VAR_0->gb) != 1) {

        

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad marker\n");

        return -1;

    }

    if (get_bits1(&VAR_0->gb) != 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad H263 id\n");

        return -1;      

    }

    skip_bits1(&VAR_0->gb);         

    skip_bits1(&VAR_0->gb);         

    skip_bits1(&VAR_0->gb);         



    VAR_1 = get_bits(&VAR_0->gb, 3);

    













    if (VAR_1 != 7 && VAR_1 != 6) {

        VAR_0->h263_plus = 0;

        

        VAR_2 = ff_h263_format[VAR_1][0];

        VAR_3 = ff_h263_format[VAR_1][1];

        if (!VAR_2)

            return -1;



        VAR_0->pict_type = AV_PICTURE_TYPE_I + get_bits1(&VAR_0->gb);



        VAR_0->h263_long_vectors = get_bits1(&VAR_0->gb);



        if (get_bits1(&VAR_0->gb) != 0) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "H263 SAC not supported\n");

            return -1; 

        }

        VAR_0->obmc= get_bits1(&VAR_0->gb); 

        VAR_0->unrestricted_mv = VAR_0->h263_long_vectors || VAR_0->obmc;



        VAR_0->pb_frame = get_bits1(&VAR_0->gb);

        VAR_0->chroma_qscale= VAR_0->qscale = get_bits(&VAR_0->gb, 5);

        skip_bits1(&VAR_0->gb); 



        VAR_0->VAR_2 = VAR_2;

        VAR_0->VAR_3 = VAR_3;

        VAR_0->avctx->sample_aspect_ratio= (AVRational){12,11};

        VAR_0->avctx->framerate = (AVRational){ 30000, 1001 };

    } else {

        int VAR_5;



        

        VAR_0->h263_plus = 1;

        VAR_5 = get_bits(&VAR_0->gb, 3); 



        

        if (VAR_5 == 1) {

            

            VAR_1 = get_bits(&VAR_0->gb, 3);

            av_dlog(VAR_0->avctx, "VAR_5=1, VAR_1: %d\n", VAR_1);

            VAR_0->custom_pcf= get_bits1(&VAR_0->gb);

            VAR_0->umvplus = get_bits1(&VAR_0->gb); 

            if (get_bits1(&VAR_0->gb) != 0) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");

            }

            VAR_0->obmc= get_bits1(&VAR_0->gb); 

            VAR_0->h263_aic = get_bits1(&VAR_0->gb); 

            VAR_0->loop_filter= get_bits1(&VAR_0->gb);

            VAR_0->unrestricted_mv = VAR_0->umvplus || VAR_0->obmc || VAR_0->loop_filter;

            if(VAR_0->avctx->lowres)

                VAR_0->loop_filter = 0;



            VAR_0->h263_slice_structured= get_bits1(&VAR_0->gb);

            if (get_bits1(&VAR_0->gb) != 0) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");

            }

            if (get_bits1(&VAR_0->gb) != 0) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");

            }

            VAR_0->alt_inter_vlc= get_bits1(&VAR_0->gb);

            VAR_0->modified_quant= get_bits1(&VAR_0->gb);

            if(VAR_0->modified_quant)

                VAR_0->chroma_qscale_table= ff_h263_chroma_qscale_table;



            skip_bits(&VAR_0->gb, 1); 



            skip_bits(&VAR_0->gb, 3); 

        } else if (VAR_5 != 0) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", VAR_5);

            return -1;

        }



        

        VAR_0->pict_type = get_bits(&VAR_0->gb, 3);

        switch(VAR_0->pict_type){

        case 0: VAR_0->pict_type= AV_PICTURE_TYPE_I;break;

        case 1: VAR_0->pict_type= AV_PICTURE_TYPE_P;break;

        case 2: VAR_0->pict_type= AV_PICTURE_TYPE_P;VAR_0->pb_frame = 3;break;

        case 3: VAR_0->pict_type= AV_PICTURE_TYPE_B;break;

        case 7: VAR_0->pict_type= AV_PICTURE_TYPE_I;break; 

        default:

            return -1;

        }

        skip_bits(&VAR_0->gb, 2);

        VAR_0->no_rounding = get_bits1(&VAR_0->gb);

        skip_bits(&VAR_0->gb, 4);



        

        if (VAR_5) {

            if (VAR_1 == 6) {

                

                VAR_0->aspect_ratio_info = get_bits(&VAR_0->gb, 4);

                av_dlog(VAR_0->avctx, "aspect: %d\n", VAR_0->aspect_ratio_info);

                

















                VAR_2 = (get_bits(&VAR_0->gb, 9) + 1) * 4;

                skip_bits1(&VAR_0->gb);

                VAR_3 = get_bits(&VAR_0->gb, 9) * 4;

                av_dlog(VAR_0->avctx, "\nH.263+ Custom picture: %dx%d\n",VAR_2,VAR_3);

                if (VAR_0->aspect_ratio_info == FF_ASPECT_EXTENDED) {

                    

                    VAR_0->avctx->sample_aspect_ratio.num= get_bits(&VAR_0->gb, 8);

                    VAR_0->avctx->sample_aspect_ratio.den= get_bits(&VAR_0->gb, 8);

                }else{

                    VAR_0->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[VAR_0->aspect_ratio_info];

                }

            } else {

                VAR_2 = ff_h263_format[VAR_1][0];

                VAR_3 = ff_h263_format[VAR_1][1];

                VAR_0->avctx->sample_aspect_ratio= (AVRational){12,11};

            }

            VAR_0->avctx->sample_aspect_ratio.den <<= VAR_0->ehc_mode;

            if ((VAR_2 == 0) || (VAR_3 == 0))

                return -1;

            VAR_0->VAR_2 = VAR_2;

            VAR_0->VAR_3 = VAR_3;



            if(VAR_0->custom_pcf){

                int VAR_6;

                VAR_0->avctx->framerate.num  = 1800000;

                VAR_0->avctx->framerate.den  = 1000 + get_bits1(&VAR_0->gb);

                VAR_0->avctx->framerate.den *= get_bits(&VAR_0->gb, 7);

                if(VAR_0->avctx->framerate.den == 0){

                    av_log(VAR_0, AV_LOG_ERROR, "zero framerate\n");

                    return -1;

                }

                VAR_6= av_gcd(VAR_0->avctx->framerate.den, VAR_0->avctx->framerate.num);

                VAR_0->avctx->framerate.den /= VAR_6;

                VAR_0->avctx->framerate.num /= VAR_6;

            }else{

                VAR_0->avctx->framerate = (AVRational){ 30000, 1001 };

            }

        }



        if(VAR_0->custom_pcf){

            skip_bits(&VAR_0->gb, 2); 

        }



        if (VAR_5) {

            if (VAR_0->umvplus) {

                if(get_bits1(&VAR_0->gb)==0) 

                    skip_bits1(&VAR_0->gb);

            }

            if(VAR_0->h263_slice_structured){

                if (get_bits1(&VAR_0->gb) != 0) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");

                }

                if (get_bits1(&VAR_0->gb) != 0) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "unordered slices not supported\n");

                }

            }

        }



        VAR_0->qscale = get_bits(&VAR_0->gb, 5);

    }



    if (VAR_0->VAR_2 == 0 || VAR_0->VAR_3 == 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "dimensions 0\n");

        return -1;

    }

    VAR_0->mb_width = (VAR_0->VAR_2  + 15) / 16;

    VAR_0->mb_height = (VAR_0->VAR_3  + 15) / 16;

    VAR_0->mb_num = VAR_0->mb_width * VAR_0->mb_height;



    if (VAR_0->pb_frame) {

        skip_bits(&VAR_0->gb, 3); 

        if (VAR_0->custom_pcf)

            skip_bits(&VAR_0->gb, 2); 

        skip_bits(&VAR_0->gb, 2); 

    }



    if (VAR_0->pict_type!=AV_PICTURE_TYPE_B) {

        VAR_0->time            = VAR_0->picture_number;

        VAR_0->pp_time         = VAR_0->time - VAR_0->last_non_b_time;

        VAR_0->last_non_b_time = VAR_0->time;

    }else{

        VAR_0->time    = VAR_0->picture_number;

        VAR_0->pb_time = VAR_0->pp_time - (VAR_0->last_non_b_time - VAR_0->time);

        if (VAR_0->pp_time <=VAR_0->pb_time ||

            VAR_0->pp_time <= VAR_0->pp_time - VAR_0->pb_time ||

            VAR_0->pp_time <= 0){

            VAR_0->pp_time = 2;

            VAR_0->pb_time = 1;

        }

        ff_mpeg4_init_direct_mv(VAR_0);

    }



    

    if (skip_1stop_8data_bits(&VAR_0->gb) < 0)

        return AVERROR_INVALIDDATA;



    if(VAR_0->h263_slice_structured){

        if (get_bits1(&VAR_0->gb) != 1) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n");

            return -1;

        }



        ff_h263_decode_mba(VAR_0);



        if (get_bits1(&VAR_0->gb) != 1) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n");

            return -1;

        }

    }

    VAR_0->f_code = 1;



    if(VAR_0->h263_aic){

         VAR_0->y_dc_scale_table=

         VAR_0->c_dc_scale_table= ff_aic_dc_scale_table;

    }else{

        VAR_0->y_dc_scale_table=

        VAR_0->c_dc_scale_table= ff_mpeg1_dc_scale_table;

    }



        ff_h263_show_pict_info(VAR_0);

    if (VAR_0->pict_type == AV_PICTURE_TYPE_I && VAR_0->codec_tag == AV_RL32("ZYGO") && get_bits_left(&VAR_0->gb) >= 85 + 13*3*16 + 50){

        int VAR_7,VAR_7;

        for(VAR_7=0; VAR_7<85; VAR_7++) av_log(VAR_0->avctx, AV_LOG_DEBUG, "%d", get_bits1(&VAR_0->gb));

        av_log(VAR_0->avctx, AV_LOG_DEBUG, "\n");

        for(VAR_7=0; VAR_7<13; VAR_7++){

            for(VAR_7=0; VAR_7<3; VAR_7++){

                int VAR_8= get_bits(&VAR_0->gb, 8);

                VAR_8 |= get_sbits(&VAR_0->gb, 8)<<8;

                av_log(VAR_0->avctx, AV_LOG_DEBUG, " %5d", VAR_8);

            }

            av_log(VAR_0->avctx, AV_LOG_DEBUG, "\n");

        }

        for(VAR_7=0; VAR_7<50; VAR_7++) av_log(VAR_0->avctx, AV_LOG_DEBUG, "%d", get_bits1(&VAR_0->gb));

    }



    return 0;

}

int FUNC_0(MpegEncContext *VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_7; uint32_t startcode; align_get_bits(&VAR_0->gb); if (show_bits(&VAR_0->gb, 2) == 2 && VAR_0->avctx->frame_number == 0) { av_log(VAR_0->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n"); } startcode= get_bits(&VAR_0->gb, 22-8); for(VAR_7= get_bits_left(&VAR_0->gb); VAR_7>24; VAR_7-=8) { startcode = ((startcode << 8) | get_bits(&VAR_0->gb, 8)) & 0x003FFFFF; if(startcode == 0x20)
break; } if (startcode != 0x20) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad picture start code\n"); return -1; } VAR_7 = get_bits(&VAR_0->gb, 8); if( (VAR_0->picture_number&~0xFF)+VAR_7 < VAR_0->picture_number)
VAR_7+= 256; VAR_0->picture_number= (VAR_0->picture_number&~0xFF) + VAR_7; if (get_bits1(&VAR_0->gb) != 1) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad marker\n"); return -1; } if (get_bits1(&VAR_0->gb) != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad H263 id\n"); return -1; } skip_bits1(&VAR_0->gb); skip_bits1(&VAR_0->gb); skip_bits1(&VAR_0->gb); VAR_1 = get_bits(&VAR_0->gb, 3); if (VAR_1 != 7 && VAR_1 != 6) { VAR_0->h263_plus = 0; VAR_2 = ff_h263_format[VAR_1][0]; VAR_3 = ff_h263_format[VAR_1][1]; if (!VAR_2)
return -1; VAR_0->pict_type = AV_PICTURE_TYPE_I + get_bits1(&VAR_0->gb); VAR_0->h263_long_vectors = get_bits1(&VAR_0->gb); if (get_bits1(&VAR_0->gb) != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "H263 SAC not supported\n"); return -1; } VAR_0->obmc= get_bits1(&VAR_0->gb); VAR_0->unrestricted_mv = VAR_0->h263_long_vectors || VAR_0->obmc; VAR_0->pb_frame = get_bits1(&VAR_0->gb); VAR_0->chroma_qscale= VAR_0->qscale = get_bits(&VAR_0->gb, 5); skip_bits1(&VAR_0->gb); VAR_0->VAR_2 = VAR_2; VAR_0->VAR_3 = VAR_3; VAR_0->avctx->sample_aspect_ratio= (AVRational){12,11}; VAR_0->avctx->framerate = (AVRational){ 30000, 1001 }; } else { int VAR_5; VAR_0->h263_plus = 1; VAR_5 = get_bits(&VAR_0->gb, 3); if (VAR_5 == 1) { VAR_1 = get_bits(&VAR_0->gb, 3); av_dlog(VAR_0->avctx, "VAR_5=1, VAR_1: %d\n", VAR_1); VAR_0->custom_pcf= get_bits1(&VAR_0->gb); VAR_0->umvplus = get_bits1(&VAR_0->gb); if (get_bits1(&VAR_0->gb) != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); } VAR_0->obmc= get_bits1(&VAR_0->gb); VAR_0->h263_aic = get_bits1(&VAR_0->gb); VAR_0->loop_filter= get_bits1(&VAR_0->gb); VAR_0->unrestricted_mv = VAR_0->umvplus || VAR_0->obmc || VAR_0->loop_filter; if(VAR_0->avctx->lowres)
VAR_0->loop_filter = 0; VAR_0->h263_slice_structured= get_bits1(&VAR_0->gb); if (get_bits1(&VAR_0->gb) != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); } if (get_bits1(&VAR_0->gb) != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); } VAR_0->alt_inter_vlc= get_bits1(&VAR_0->gb); VAR_0->modified_quant= get_bits1(&VAR_0->gb); if(VAR_0->modified_quant)
VAR_0->chroma_qscale_table= ff_h263_chroma_qscale_table; skip_bits(&VAR_0->gb, 1); skip_bits(&VAR_0->gb, 3); } else if (VAR_5 != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", VAR_5); return -1; } VAR_0->pict_type = get_bits(&VAR_0->gb, 3); switch(VAR_0->pict_type){ case 0: VAR_0->pict_type= AV_PICTURE_TYPE_I;break; case 1: VAR_0->pict_type= AV_PICTURE_TYPE_P;break; case 2: VAR_0->pict_type= AV_PICTURE_TYPE_P;VAR_0->pb_frame = 3;break; case 3: VAR_0->pict_type= AV_PICTURE_TYPE_B;break; case 7: VAR_0->pict_type= AV_PICTURE_TYPE_I;break; default:
return -1; } skip_bits(&VAR_0->gb, 2); VAR_0->no_rounding = get_bits1(&VAR_0->gb); skip_bits(&VAR_0->gb, 4); if (VAR_5) { if (VAR_1 == 6) { VAR_0->aspect_ratio_info = get_bits(&VAR_0->gb, 4); av_dlog(VAR_0->avctx, "aspect: %d\n", VAR_0->aspect_ratio_info); VAR_2 = (get_bits(&VAR_0->gb, 9) + 1) * 4; skip_bits1(&VAR_0->gb); VAR_3 = get_bits(&VAR_0->gb, 9) * 4; av_dlog(VAR_0->avctx, "\nH.263+ Custom picture: %dx%d\n",VAR_2,VAR_3); if (VAR_0->aspect_ratio_info == FF_ASPECT_EXTENDED) { VAR_0->avctx->sample_aspect_ratio.num= get_bits(&VAR_0->gb, 8); VAR_0->avctx->sample_aspect_ratio.den= get_bits(&VAR_0->gb, 8); }else{ VAR_0->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[VAR_0->aspect_ratio_info]; } } else { VAR_2 = ff_h263_format[VAR_1][0]; VAR_3 = ff_h263_format[VAR_1][1]; VAR_0->avctx->sample_aspect_ratio= (AVRational){12,11}; } VAR_0->avctx->sample_aspect_ratio.den <<= VAR_0->ehc_mode; if ((VAR_2 == 0) || (VAR_3 == 0))
return -1; VAR_0->VAR_2 = VAR_2; VAR_0->VAR_3 = VAR_3; if(VAR_0->custom_pcf){ int VAR_6; VAR_0->avctx->framerate.num  = 1800000; VAR_0->avctx->framerate.den  = 1000 + get_bits1(&VAR_0->gb); VAR_0->avctx->framerate.den *= get_bits(&VAR_0->gb, 7); if(VAR_0->avctx->framerate.den == 0){ av_log(VAR_0, AV_LOG_ERROR, "zero framerate\n"); return -1; } VAR_6= av_gcd(VAR_0->avctx->framerate.den, VAR_0->avctx->framerate.num); VAR_0->avctx->framerate.den /= VAR_6; VAR_0->avctx->framerate.num /= VAR_6; }else{ VAR_0->avctx->framerate = (AVRational){ 30000, 1001 }; } } if(VAR_0->custom_pcf){ skip_bits(&VAR_0->gb, 2); } if (VAR_5) { if (VAR_0->umvplus) { if(get_bits1(&VAR_0->gb)==0)
skip_bits1(&VAR_0->gb); } if(VAR_0->h263_slice_structured){ if (get_bits1(&VAR_0->gb) != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); } if (get_bits1(&VAR_0->gb) != 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "unordered slices not supported\n"); } } } VAR_0->qscale = get_bits(&VAR_0->gb, 5); } if (VAR_0->VAR_2 == 0 || VAR_0->VAR_3 == 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "dimensions 0\n"); return -1; } VAR_0->mb_width = (VAR_0->VAR_2  + 15) / 16; VAR_0->mb_height = (VAR_0->VAR_3  + 15) / 16; VAR_0->mb_num = VAR_0->mb_width * VAR_0->mb_height; if (VAR_0->pb_frame) { skip_bits(&VAR_0->gb, 3); if (VAR_0->custom_pcf)
skip_bits(&VAR_0->gb, 2); skip_bits(&VAR_0->gb, 2); } if (VAR_0->pict_type!=AV_PICTURE_TYPE_B) { VAR_0->time            = VAR_0->picture_number; VAR_0->pp_time         = VAR_0->time - VAR_0->last_non_b_time; VAR_0->last_non_b_time = VAR_0->time; }else{ VAR_0->time    = VAR_0->picture_number; VAR_0->pb_time = VAR_0->pp_time - (VAR_0->last_non_b_time - VAR_0->time); if (VAR_0->pp_time <=VAR_0->pb_time ||
VAR_0->pp_time <= VAR_0->pp_time - VAR_0->pb_time ||
VAR_0->pp_time <= 0){ VAR_0->pp_time = 2; VAR_0->pb_time = 1; } ff_mpeg4_init_direct_mv(VAR_0); } if (skip_1stop_8data_bits(&VAR_0->gb) < 0)
return AVERROR_INVALIDDATA; if(VAR_0->h263_slice_structured){ if (get_bits1(&VAR_0->gb) != 1) { av_log(VAR_0->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n"); return -1; } ff_h263_decode_mba(VAR_0); if (get_bits1(&VAR_0->gb) != 1) { av_log(VAR_0->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n"); return -1; } } VAR_0->f_code = 1; if(VAR_0->h263_aic){ VAR_0->y_dc_scale_table=
VAR_0->c_dc_scale_table= ff_aic_dc_scale_table; }else{ VAR_0->y_dc_scale_table=
VAR_0->c_dc_scale_table= ff_mpeg1_dc_scale_table; } ff_h263_show_pict_info(VAR_0); if (VAR_0->pict_type == AV_PICTURE_TYPE_I && VAR_0->codec_tag == AV_RL32("ZYGO") && get_bits_left(&VAR_0->gb) >= 85 + 13*3*16 + 50){ int VAR_7,VAR_7; for(VAR_7=0; VAR_7<85; VAR_7++) av_log(VAR_0->avctx, AV_LOG_DEBUG, "%d", get_bits1(&VAR_0->gb)); av_log(VAR_0->avctx, AV_LOG_DEBUG, "\n"); for(VAR_7=0; VAR_7<13; VAR_7++){ for(VAR_7=0; VAR_7<3; VAR_7++){ int VAR_8= get_bits(&VAR_0->gb, 8); VAR_8 |= get_sbits(&VAR_0->gb, 8)<<8; av_log(VAR_0->avctx, AV_LOG_DEBUG, " %5d", VAR_8); } av_log(VAR_0->avctx, AV_LOG_DEBUG, "\n"); } for(VAR_7=0; VAR_7<50; VAR_7++) av_log(VAR_0->avctx, AV_LOG_DEBUG, "%d", get_bits1(&VAR_0->gb)); } return 0; }