static int encode_init(AVCodecContext * avctx){

    WMACodecContext *s = avctx->priv_data;

    int i, flags1, flags2;

    uint8_t *extradata;



    s->avctx = avctx;



    if(avctx->channels > MAX_CHANNELS) {

        av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer",

               avctx->channels, MAX_CHANNELS);

        return AVERROR(EINVAL);

    }



    if (avctx->sample_rate > 48000) {

        av_log(avctx, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz",

               avctx->sample_rate);

        return AVERROR(EINVAL);

    }



    if(avctx->bit_rate < 24*1000) {

        av_log(avctx, AV_LOG_ERROR, "bitrate too low: got %i, need 24000 or higher\n",

               avctx->bit_rate);

        return AVERROR(EINVAL);

    }



    /* extract flag infos */

    flags1 = 0;

    flags2 = 1;

    if (avctx->codec->id == CODEC_ID_WMAV1) {

        extradata= av_malloc(4);

        avctx->extradata_size= 4;

        AV_WL16(extradata, flags1);

        AV_WL16(extradata+2, flags2);

    } else if (avctx->codec->id == CODEC_ID_WMAV2) {

        extradata= av_mallocz(10);

        avctx->extradata_size= 10;

        AV_WL32(extradata, flags1);

        AV_WL16(extradata+4, flags2);

    }else

        av_assert0(0);

    avctx->extradata= extradata;

    s->use_exp_vlc = flags2 & 0x0001;

    s->use_bit_reservoir = flags2 & 0x0002;

    s->use_variable_block_len = flags2 & 0x0004;

    if (avctx->channels == 2)

        s->ms_stereo = 1;



    ff_wma_init(avctx, flags2);



    /* init MDCT */

    for(i = 0; i < s->nb_block_sizes; i++)

        ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0);



    s->block_align     = avctx->bit_rate * (int64_t)s->frame_len /

                         (avctx->sample_rate * 8);

    s->block_align     = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE);

    avctx->block_align = s->block_align;

    avctx->bit_rate    = avctx->block_align * 8LL * avctx->sample_rate /

                         s->frame_len;

//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", s->block_align, avctx->bit_rate, s->frame_len, avctx->sample_rate);

    avctx->frame_size = avctx->delay = s->frame_len;



#if FF_API_OLD_ENCODE_AUDIO

    avctx->coded_frame = &s->frame;

    avcodec_get_frame_defaults(avctx->coded_frame);

#endif



    return 0;

}

static int encode_init(AVCodecContext * avctx){

    WMACodecContext *s = avctx->priv_data;

    int i, flags1, flags2;

    uint8_t *extradata;



    s->avctx = avctx;



    if(avctx->channels > MAX_CHANNELS) {

        av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer",

               avctx->channels, MAX_CHANNELS);

        return AVERROR(EINVAL);

    }



    if (avctx->sample_rate > 48000) {

        av_log(avctx, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz",

               avctx->sample_rate);

        return AVERROR(EINVAL);

    }



    if(avctx->bit_rate < 24*1000) {

        av_log(avctx, AV_LOG_ERROR, "bitrate too low: got %i, need 24000 or higher\n",

               avctx->bit_rate);

        return AVERROR(EINVAL);

    }



    

    flags1 = 0;

    flags2 = 1;

    if (avctx->codec->id == CODEC_ID_WMAV1) {

        extradata= av_malloc(4);

        avctx->extradata_size= 4;

        AV_WL16(extradata, flags1);

        AV_WL16(extradata+2, flags2);

    } else if (avctx->codec->id == CODEC_ID_WMAV2) {

        extradata= av_mallocz(10);

        avctx->extradata_size= 10;

        AV_WL32(extradata, flags1);

        AV_WL16(extradata+4, flags2);

    }else

        av_assert0(0);

    avctx->extradata= extradata;

    s->use_exp_vlc = flags2 & 0x0001;

    s->use_bit_reservoir = flags2 & 0x0002;

    s->use_variable_block_len = flags2 & 0x0004;

    if (avctx->channels == 2)

        s->ms_stereo = 1;



    ff_wma_init(avctx, flags2);



    

    for(i = 0; i < s->nb_block_sizes; i++)

        ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0);



    s->block_align     = avctx->bit_rate * (int64_t)s->frame_len /

                         (avctx->sample_rate * 8);

    s->block_align     = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE);

    avctx->block_align = s->block_align;

    avctx->bit_rate    = avctx->block_align * 8LL * avctx->sample_rate /

                         s->frame_len;



    avctx->frame_size = avctx->delay = s->frame_len;



#if FF_API_OLD_ENCODE_AUDIO

    avctx->coded_frame = &s->frame;

    avcodec_get_frame_defaults(avctx->coded_frame);

#endif



    return 0;

}

static int FUNC_0(AVCodecContext * VAR_0){

    WMACodecContext *s = VAR_0->priv_data;

    int VAR_1, VAR_2, VAR_3;

    uint8_t *extradata;



    s->VAR_0 = VAR_0;



    if(VAR_0->channels > MAX_CHANNELS) {

        av_log(VAR_0, AV_LOG_ERROR, "too many channels: got %VAR_1, need %VAR_1 or fewer",

               VAR_0->channels, MAX_CHANNELS);

        return AVERROR(EINVAL);

    }



    if (VAR_0->sample_rate > 48000) {

        av_log(VAR_0, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz",

               VAR_0->sample_rate);

        return AVERROR(EINVAL);

    }



    if(VAR_0->bit_rate < 24*1000) {

        av_log(VAR_0, AV_LOG_ERROR, "bitrate too low: got %VAR_1, need 24000 or higher\n",

               VAR_0->bit_rate);

        return AVERROR(EINVAL);

    }



    

    VAR_2 = 0;

    VAR_3 = 1;

    if (VAR_0->codec->id == CODEC_ID_WMAV1) {

        extradata= av_malloc(4);

        VAR_0->extradata_size= 4;

        AV_WL16(extradata, VAR_2);

        AV_WL16(extradata+2, VAR_3);

    } else if (VAR_0->codec->id == CODEC_ID_WMAV2) {

        extradata= av_mallocz(10);

        VAR_0->extradata_size= 10;

        AV_WL32(extradata, VAR_2);

        AV_WL16(extradata+4, VAR_3);

    }else

        av_assert0(0);

    VAR_0->extradata= extradata;

    s->use_exp_vlc = VAR_3 & 0x0001;

    s->use_bit_reservoir = VAR_3 & 0x0002;

    s->use_variable_block_len = VAR_3 & 0x0004;

    if (VAR_0->channels == 2)

        s->ms_stereo = 1;



    ff_wma_init(VAR_0, VAR_3);



    

    for(VAR_1 = 0; VAR_1 < s->nb_block_sizes; VAR_1++)

        ff_mdct_init(&s->mdct_ctx[VAR_1], s->frame_len_bits - VAR_1 + 1, 0, 1.0);



    s->block_align     = VAR_0->bit_rate * (int64_t)s->frame_len /

                         (VAR_0->sample_rate * 8);

    s->block_align     = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE);

    VAR_0->block_align = s->block_align;

    VAR_0->bit_rate    = VAR_0->block_align * 8LL * VAR_0->sample_rate /

                         s->frame_len;



    VAR_0->frame_size = VAR_0->delay = s->frame_len;



#if FF_API_OLD_ENCODE_AUDIO

    VAR_0->coded_frame = &s->frame;

    avcodec_get_frame_defaults(VAR_0->coded_frame);

#endif



    return 0;

}

static int FUNC_0(AVCodecContext * VAR_0){ WMACodecContext *s = VAR_0->priv_data; int VAR_1, VAR_2, VAR_3; uint8_t *extradata; s->VAR_0 = VAR_0; if(VAR_0->channels > MAX_CHANNELS) { av_log(VAR_0, AV_LOG_ERROR, "too many channels: got %VAR_1, need %VAR_1 or fewer",
VAR_0->channels, MAX_CHANNELS); return AVERROR(EINVAL); } if (VAR_0->sample_rate > 48000) { av_log(VAR_0, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz",
VAR_0->sample_rate); return AVERROR(EINVAL); } if(VAR_0->bit_rate < 24*1000) { av_log(VAR_0, AV_LOG_ERROR, "bitrate too low: got %VAR_1, need 24000 or higher\n",
VAR_0->bit_rate); return AVERROR(EINVAL); } VAR_2 = 0; VAR_3 = 1; if (VAR_0->codec->id == CODEC_ID_WMAV1) { extradata= av_malloc(4); VAR_0->extradata_size= 4; AV_WL16(extradata, VAR_2); AV_WL16(extradata+2, VAR_3); } else if (VAR_0->codec->id == CODEC_ID_WMAV2) { extradata= av_mallocz(10); VAR_0->extradata_size= 10; AV_WL32(extradata, VAR_2); AV_WL16(extradata+4, VAR_3); }else av_assert0(0); VAR_0->extradata= extradata; s->use_exp_vlc = VAR_3 & 0x0001; s->use_bit_reservoir = VAR_3 & 0x0002; s->use_variable_block_len = VAR_3 & 0x0004; if (VAR_0->channels == 2)
s->ms_stereo = 1; ff_wma_init(VAR_0, VAR_3); for(VAR_1 = 0; VAR_1 < s->nb_block_sizes; VAR_1++) ff_mdct_init(&s->mdct_ctx[VAR_1], s->frame_len_bits - VAR_1 + 1, 0, 1.0); s->block_align     = VAR_0->bit_rate * (int64_t)s->frame_len /
(VAR_0->sample_rate * 8); s->block_align     = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE); VAR_0->block_align = s->block_align; VAR_0->bit_rate    = VAR_0->block_align * 8LL * VAR_0->sample_rate /
s->frame_len; VAR_0->frame_size = VAR_0->delay = s->frame_len; #if FF_API_OLD_ENCODE_AUDIO
VAR_0->coded_frame = &s->frame; avcodec_get_frame_defaults(VAR_0->coded_frame); #endif
return 0; }