void MPV_common_end(MpegEncContext *s)
{
    int i, j, k;
    for(i=0; i<s->avctx->thread_count; i++){
        free_duplicate_context(s->thread_context[i]);
    }
    for(i=1; i<s->avctx->thread_count; i++){
        av_freep(&s->thread_context[i]);
    }
    av_freep(&s->parse_context.buffer);
    s->parse_context.buffer_size=0;
    av_freep(&s->mb_type);
    av_freep(&s->p_mv_table_base);
    av_freep(&s->b_forw_mv_table_base);
    av_freep(&s->b_back_mv_table_base);
    av_freep(&s->b_bidir_forw_mv_table_base);
    av_freep(&s->b_bidir_back_mv_table_base);
    av_freep(&s->b_direct_mv_table_base);
    s->p_mv_table= NULL;
    s->b_forw_mv_table= NULL;
    s->b_back_mv_table= NULL;
    s->b_bidir_forw_mv_table= NULL;
    s->b_bidir_back_mv_table= NULL;
    s->b_direct_mv_table= NULL;
    for(i=0; i<2; i++){
        for(j=0; j<2; j++){
            for(k=0; k<2; k++){
                av_freep(&s->b_field_mv_table_base[i][j][k]);
                s->b_field_mv_table[i][j][k]=NULL;
            }
            av_freep(&s->b_field_select_table[i][j]);
            av_freep(&s->p_field_mv_table_base[i][j]);
            s->p_field_mv_table[i][j]=NULL;
        }
        av_freep(&s->p_field_select_table[i]);
    }
    av_freep(&s->dc_val_base);
    av_freep(&s->ac_val_base);
    av_freep(&s->coded_block_base);
    av_freep(&s->mbintra_table);
    av_freep(&s->cbp_table);
    av_freep(&s->pred_dir_table);
    av_freep(&s->mbskip_table);
    av_freep(&s->prev_pict_types);
    av_freep(&s->bitstream_buffer);
    s->allocated_bitstream_buffer_size=0;
    av_freep(&s->avctx->stats_out);
    av_freep(&s->ac_stats);
    av_freep(&s->error_status_table);
    av_freep(&s->mb_index2xy);
    av_freep(&s->lambda_table);
    av_freep(&s->q_intra_matrix);
    av_freep(&s->q_inter_matrix);
    av_freep(&s->q_intra_matrix16);
    av_freep(&s->q_inter_matrix16);
    av_freep(&s->input_picture);
    av_freep(&s->reordered_input_picture);
    av_freep(&s->dct_offset);
    if(s->picture){
        for(i=0; i<MAX_PICTURE_COUNT; i++){
            free_picture(s, &s->picture[i]);
        }
    }
    av_freep(&s->picture);
    s->context_initialized = 0;
    s->last_picture_ptr=
    s->next_picture_ptr=
    s->current_picture_ptr= NULL;
    s->linesize= s->uvlinesize= 0;
    for(i=0; i<3; i++)
        av_freep(&s->visualization_buffer[i]);
    avcodec_default_free_buffers(s->avctx);
}
['static int h261_decode_frame(AVCodecContext *avctx,\n                             void *data, int *data_size,\n                             const uint8_t *buf, int buf_size)\n{\n    H261Context *h= avctx->priv_data;\n    MpegEncContext *s = &h->s;\n    int ret;\n    AVFrame *pict = data;\n#ifdef DEBUG\n    av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\\n", avctx->frame_number, buf_size);\n    av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\\n", buf[0], buf[1], buf[2], buf[3]);\n#endif\n    s->flags= avctx->flags;\n    s->flags2= avctx->flags2;\n    h->gob_start_code_skipped=0;\nretry:\n    init_get_bits(&s->gb, buf, buf_size*8);\n    if(!s->context_initialized){\n        if (MPV_common_init(s) < 0)\n            return -1;\n    }\n    if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){\n        int i= ff_find_unused_picture(s, 0);\n        s->current_picture_ptr= &s->picture[i];\n    }\n    ret = h261_decode_picture_header(h);\n    if (ret < 0){\n        av_log(s->avctx, AV_LOG_ERROR, "header damaged\\n");\n        return -1;\n    }\n    if (s->width != avctx->coded_width || s->height != avctx->coded_height){\n        ParseContext pc= s->parse_context;\n        s->parse_context.buffer=0;\n        MPV_common_end(s);\n        s->parse_context= pc;\n    }\n    if (!s->context_initialized) {\n        avcodec_set_dimensions(avctx, s->width, s->height);\n        goto retry;\n    }\n    s->current_picture.pict_type= s->pict_type;\n    s->current_picture.key_frame= s->pict_type == FF_I_TYPE;\n    if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);\n    if(  (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE)\n       ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE)\n       || avctx->skip_frame >= AVDISCARD_ALL)\n        return get_consumed_bytes(s, buf_size);\n    if(MPV_frame_start(s, avctx) < 0)\n        return -1;\n    ff_er_frame_start(s);\n    s->mb_x=0;\n    s->mb_y=0;\n    while(h->gob_number < (s->mb_height==18 ? 12 : 5)){\n        if(ff_h261_resync(h)<0)\n            break;\n        h261_decode_gob(h);\n    }\n    MPV_frame_end(s);\nassert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);\nassert(s->current_picture.pict_type == s->pict_type);\n    *pict= *(AVFrame*)s->current_picture_ptr;\n    ff_print_debug_info(s, pict);\n    *data_size = sizeof(AVFrame);\n    return get_consumed_bytes(s, buf_size);\n}', 'static int h261_decode_picture_header(H261Context *h){\n    MpegEncContext * const s = &h->s;\n    int format, i;\n    uint32_t startcode= 0;\n    for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){\n        startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;\n        if(startcode == 0x10)\n            break;\n    }\n    if (startcode != 0x10){\n        av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\\n");\n        return -1;\n    }\n    i= get_bits(&s->gb, 5);\n    if(i < (s->picture_number&31))\n        i += 32;\n    s->picture_number = (s->picture_number&~31) + i;\n    s->avctx->time_base= (AVRational){1001, 30000};\n    s->current_picture.pts= s->picture_number;\n    skip_bits1(&s->gb);\n    skip_bits1(&s->gb);\n    skip_bits1(&s->gb);\n    format = get_bits1(&s->gb);\n    if (format == 0){\n        s->width = 176;\n        s->height = 144;\n        s->mb_width = 11;\n        s->mb_height = 9;\n    }else{\n        s->width = 352;\n        s->height = 288;\n        s->mb_width = 22;\n        s->mb_height = 18;\n    }\n    s->mb_num = s->mb_width * s->mb_height;\n    skip_bits1(&s->gb);\n    skip_bits1(&s->gb);\n    while (get_bits1(&s->gb) != 0){\n        skip_bits(&s->gb, 8);\n    }\n    s->pict_type = FF_P_TYPE;\n    h->gob_number = 0;\n    return 0;\n}', 'void MPV_common_end(MpegEncContext *s)\n{\n    int i, j, k;\n    for(i=0; i<s->avctx->thread_count; i++){\n        free_duplicate_context(s->thread_context[i]);\n    }\n    for(i=1; i<s->avctx->thread_count; i++){\n        av_freep(&s->thread_context[i]);\n    }\n    av_freep(&s->parse_context.buffer);\n    s->parse_context.buffer_size=0;\n    av_freep(&s->mb_type);\n    av_freep(&s->p_mv_table_base);\n    av_freep(&s->b_forw_mv_table_base);\n    av_freep(&s->b_back_mv_table_base);\n    av_freep(&s->b_bidir_forw_mv_table_base);\n    av_freep(&s->b_bidir_back_mv_table_base);\n    av_freep(&s->b_direct_mv_table_base);\n    s->p_mv_table= NULL;\n    s->b_forw_mv_table= NULL;\n    s->b_back_mv_table= NULL;\n    s->b_bidir_forw_mv_table= NULL;\n    s->b_bidir_back_mv_table= NULL;\n    s->b_direct_mv_table= NULL;\n    for(i=0; i<2; i++){\n        for(j=0; j<2; j++){\n            for(k=0; k<2; k++){\n                av_freep(&s->b_field_mv_table_base[i][j][k]);\n                s->b_field_mv_table[i][j][k]=NULL;\n            }\n            av_freep(&s->b_field_select_table[i][j]);\n            av_freep(&s->p_field_mv_table_base[i][j]);\n            s->p_field_mv_table[i][j]=NULL;\n        }\n        av_freep(&s->p_field_select_table[i]);\n    }\n    av_freep(&s->dc_val_base);\n    av_freep(&s->ac_val_base);\n    av_freep(&s->coded_block_base);\n    av_freep(&s->mbintra_table);\n    av_freep(&s->cbp_table);\n    av_freep(&s->pred_dir_table);\n    av_freep(&s->mbskip_table);\n    av_freep(&s->prev_pict_types);\n    av_freep(&s->bitstream_buffer);\n    s->allocated_bitstream_buffer_size=0;\n    av_freep(&s->avctx->stats_out);\n    av_freep(&s->ac_stats);\n    av_freep(&s->error_status_table);\n    av_freep(&s->mb_index2xy);\n    av_freep(&s->lambda_table);\n    av_freep(&s->q_intra_matrix);\n    av_freep(&s->q_inter_matrix);\n    av_freep(&s->q_intra_matrix16);\n    av_freep(&s->q_inter_matrix16);\n    av_freep(&s->input_picture);\n    av_freep(&s->reordered_input_picture);\n    av_freep(&s->dct_offset);\n    if(s->picture){\n        for(i=0; i<MAX_PICTURE_COUNT; i++){\n            free_picture(s, &s->picture[i]);\n        }\n    }\n    av_freep(&s->picture);\n    s->context_initialized = 0;\n    s->last_picture_ptr=\n    s->next_picture_ptr=\n    s->current_picture_ptr= NULL;\n    s->linesize= s->uvlinesize= 0;\n    for(i=0; i<3; i++)\n        av_freep(&s->visualization_buffer[i]);\n    avcodec_default_free_buffers(s->avctx);\n}']