static int decode_frame(AVCodecContext *avctx,
                        void *data, int *data_size,
                        const uint8_t *buf, int buf_size)
{
    ASV1Context * const a = avctx->priv_data;
    AVFrame *picture = data;
    AVFrame * const p= (AVFrame*)&a->picture;
    int mb_x, mb_y;
    if(p->data[0])
        avctx->release_buffer(avctx, p);
    p->reference= 0;
    if(avctx->get_buffer(avctx, p) < 0){
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return -1;
    }
    p->pict_type= FF_I_TYPE;
    p->key_frame= 1;
    a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
    if(avctx->codec_id == CODEC_ID_ASV1)
        a->dsp.bswap_buf((uint32_t*)a->bitstream_buffer, (const uint32_t*)buf, buf_size/4);
    else{
        int i;
        for(i=0; i<buf_size; i++)
            a->bitstream_buffer[i]= ff_reverse[ buf[i] ];
    }
    init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8);
    for(mb_y=0; mb_y<a->mb_height2; mb_y++){
        for(mb_x=0; mb_x<a->mb_width2; mb_x++){
            if( decode_mb(a, a->block) <0)
                return -1;
            idct_put(a, mb_x, mb_y);
        }
    }
    if(a->mb_width2 != a->mb_width){
        mb_x= a->mb_width2;
        for(mb_y=0; mb_y<a->mb_height2; mb_y++){
            if( decode_mb(a, a->block) <0)
                return -1;
            idct_put(a, mb_x, mb_y);
        }
    }
    if(a->mb_height2 != a->mb_height){
        mb_y= a->mb_height2;
        for(mb_x=0; mb_x<a->mb_width; mb_x++){
            if( decode_mb(a, a->block) <0)
                return -1;
            idct_put(a, mb_x, mb_y);
        }
    }
#if 0
int i;
printf("%d %d\n", 8*buf_size, get_bits_count(&a->gb));
for(i=get_bits_count(&a->gb); i<8*buf_size; i++){
    printf("%d", get_bits1(&a->gb));
}
for(i=0; i<s->avctx->extradata_size; i++){
    printf("%c\n", ((uint8_t*)s->avctx->extradata)[i]);
}
#endif
    *picture= *(AVFrame*)&a->picture;
    *data_size = sizeof(AVPicture);
    emms_c();
    return (get_bits_count(&a->gb)+31)/32*4;
}
['static int decode_frame(AVCodecContext *avctx,\n                        void *data, int *data_size,\n                        const uint8_t *buf, int buf_size)\n{\n    ASV1Context * const a = avctx->priv_data;\n    AVFrame *picture = data;\n    AVFrame * const p= (AVFrame*)&a->picture;\n    int mb_x, mb_y;\n    if(p->data[0])\n        avctx->release_buffer(avctx, p);\n    p->reference= 0;\n    if(avctx->get_buffer(avctx, p) < 0){\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n        return -1;\n    }\n    p->pict_type= FF_I_TYPE;\n    p->key_frame= 1;\n    a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);\n    if(avctx->codec_id == CODEC_ID_ASV1)\n        a->dsp.bswap_buf((uint32_t*)a->bitstream_buffer, (const uint32_t*)buf, buf_size/4);\n    else{\n        int i;\n        for(i=0; i<buf_size; i++)\n            a->bitstream_buffer[i]= ff_reverse[ buf[i] ];\n    }\n    init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8);\n    for(mb_y=0; mb_y<a->mb_height2; mb_y++){\n        for(mb_x=0; mb_x<a->mb_width2; mb_x++){\n            if( decode_mb(a, a->block) <0)\n                return -1;\n            idct_put(a, mb_x, mb_y);\n        }\n    }\n    if(a->mb_width2 != a->mb_width){\n        mb_x= a->mb_width2;\n        for(mb_y=0; mb_y<a->mb_height2; mb_y++){\n            if( decode_mb(a, a->block) <0)\n                return -1;\n            idct_put(a, mb_x, mb_y);\n        }\n    }\n    if(a->mb_height2 != a->mb_height){\n        mb_y= a->mb_height2;\n        for(mb_x=0; mb_x<a->mb_width; mb_x++){\n            if( decode_mb(a, a->block) <0)\n                return -1;\n            idct_put(a, mb_x, mb_y);\n        }\n    }\n#if 0\nint i;\nprintf("%d %d\\n", 8*buf_size, get_bits_count(&a->gb));\nfor(i=get_bits_count(&a->gb); i<8*buf_size; i++){\n    printf("%d", get_bits1(&a->gb));\n}\nfor(i=0; i<s->avctx->extradata_size; i++){\n    printf("%c\\n", ((uint8_t*)s->avctx->extradata)[i]);\n}\n#endif\n    *picture= *(AVFrame*)&a->picture;\n    *data_size = sizeof(AVPicture);\n    emms_c();\n    return (get_bits_count(&a->gb)+31)/32*4;\n}', 'void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)\n{\n    if(min_size < *size)\n        return ptr;\n    *size= FFMAX(17*min_size/16 + 32, min_size);\n    ptr= av_realloc(ptr, *size);\n    if(!ptr)\n        *size= 0;\n    return ptr;\n}', 'void *av_realloc(void *ptr, unsigned int size)\n{\n#ifdef CONFIG_MEMALIGN_HACK\n    int diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n    if(!ptr) return av_malloc(size);\n    diff= ((char*)ptr)[-1];\n    return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n    return realloc(ptr, size);\n#endif\n}']