int16_t mid, side;
int mid, side;
static int flac_decode_frame(AVCodecContext *avctx,                            void *data, int *data_size,                            uint8_t *buf, int buf_size){    FLACContext *s = avctx->priv_data;    int metadata_flag, metadata_type, metadata_size;    int tmp = 0, i, j = 0;    int16_t *samples = data, *left, *right;    *data_size = 0;    s->avctx = avctx;    init_get_bits(&s->gb, buf, buf_size*8);        /* fLaC signature (be) */    if (get_bits_long(&s->gb, 32) == bswap_32(ff_get_fourcc("fLaC")))    {        printf("STREAM HEADER\n");        do {            metadata_flag = get_bits(&s->gb, 1);            metadata_type = get_bits(&s->gb, 7);            metadata_size = get_bits_long(&s->gb, 24);                        printf(" metadata block: flag = %d, type = %d, size = %d\n",                metadata_flag, metadata_type,                metadata_size);            switch(metadata_type)            {                case METADATA_TYPE_STREAMINFO:                    metadata_streaminfo(s);                    dump_headers(s);                    break;                default:                    while ((metadata_size -= 8) > 0)                        skip_bits(&s->gb, 8);            }        } while(metadata_flag != 1);    }    else    {        init_get_bits(&s->gb, buf, buf_size*8);        tmp = get_bits(&s->gb, 16);        if (tmp == 0xfff8)            printf("FRAME HEADER\n");        if (decode_frame(s) < 0)            return -1;    }    #if 0    /* fix the channel order here */    if (s->order == MID_SIDE)    {        short *left = samples;        short *right = samples + s->blocksize;        for (i = 0; i < s->blocksize; i += 2)        {            uint32_t x = s->decoded[0][i];            uint32_t y = s->decoded[0][i+1];            right[i] = x - (y / 2);            left[i] = right[i] + y;        }        *data_size = 2 * s->blocksize;    }    else    {    for (i = 0; i < s->channels; i++)    {        switch(s->order)        {            case INDEPENDENT:                for (j = 0; j < s->blocksize; j++)                    samples[(s->blocksize*i)+j] = s->decoded[i][j];                break;            case LEFT_SIDE:            case RIGHT_SIDE:                if (i == 0)                    for (j = 0; j < s->blocksize; j++)                        samples[(s->blocksize*i)+j] = s->decoded[0][j];                else                    for (j = 0; j < s->blocksize; j++)                        samples[(s->blocksize*i)+j] = s->decoded[0][j] - s->decoded[i][j];                break;//            case MID_SIDE://                printf("mid-side unsupported\n");        }        *data_size += s->blocksize;    }    }#else    switch(s->order)    {        case INDEPENDENT:            for (i = 0; i < s->channels; i++)            {                for (j = 0; j < s->blocksize; j++)                    *(samples++) = s->decoded[i][j];                *data_size += s->blocksize;            }            break;        case LEFT_SIDE:            assert(s->channels == 2);            for (i = 0; i < s->blocksize; i++)            {                *(samples++) = s->decoded[0][i];                *(samples++) = s->decoded[0][i] - s->decoded[1][i];            }            *data_size = 2*s->blocksize;            break;        case RIGHT_SIDE:            assert(s->channels == 2);            for (i = 0; i < s->blocksize; i++)            {                *(samples++) = s->decoded[0][i] + s->decoded[1][i];                *(samples++) = s->decoded[1][i];            }            *data_size = 2*s->blocksize;            break;        case MID_SIDE:            assert(s->channels == 2);            for (i = 0; i < s->blocksize; i++)            {                int16_t mid, side;                mid = s->decoded[0][i];                side = s->decoded[1][i];                                mid <<= 1;                if (side & 1)                    mid++;                *(samples++) = (mid + side) >> 1;                *(samples++) = (mid - side) >> 1;            }            *data_size = 2*s->blocksize;            break;    }#endif//    *data_size = (int8_t *)samples - (int8_t *)data;    printf("data size: %d\n", *data_size);    s->last_blocksize = s->blocksize;    return (get_bits_count(&s->gb)+7)/8;}