static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,

                             int buf_size, void *data)

{

    FlacEncodeContext *s;

    const int16_t *samples = data;

    int frame_bytes, out_bytes;



    s = avctx->priv_data;



    /* when the last block is reached, update the header in extradata */

    if (!data) {

        s->max_framesize = s->max_encoded_framesize;

        av_md5_final(s->md5ctx, s->md5sum);

        write_streaminfo(s, avctx->extradata);

        return 0;

    }



    /* change max_framesize for small final frame */

    if (avctx->frame_size < s->frame.blocksize) {

        s->max_framesize = ff_flac_get_max_frame_size(avctx->frame_size,

                                                      s->channels, 16);

    }



    init_frame(s);



    copy_samples(s, samples);



    channel_decorrelation(s);



    frame_bytes = encode_frame(s);

    if (buf_size < frame_bytes) {

        av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");

        return 0;

    }

    out_bytes = write_frame(s, frame, buf_size);



    /* fallback to verbatim mode if the compressed frame is larger than it

       would be if encoded uncompressed. */

    if (out_bytes > s->max_framesize) {

        s->frame.verbatim_only = 1;

        frame_bytes = encode_frame(s);

        if (buf_size < frame_bytes) {

            av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");

            return 0;

        }

        out_bytes = write_frame(s, frame, buf_size);

    }



    s->frame_count++;

    avctx->coded_frame->pts = s->sample_count;

    s->sample_count += avctx->frame_size;

    update_md5_sum(s, samples);

    if (out_bytes > s->max_encoded_framesize)

        s->max_encoded_framesize = out_bytes;

    if (out_bytes < s->min_framesize)

        s->min_framesize = out_bytes;



    return out_bytes;

}

static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,

                             int buf_size, void *data)

{

    FlacEncodeContext *s;

    const int16_t *samples = data;

    int frame_bytes, out_bytes;



    s = avctx->priv_data;



    

    if (!data) {

        s->max_framesize = s->max_encoded_framesize;

        av_md5_final(s->md5ctx, s->md5sum);

        write_streaminfo(s, avctx->extradata);

        return 0;

    }



    

    if (avctx->frame_size < s->frame.blocksize) {

        s->max_framesize = ff_flac_get_max_frame_size(avctx->frame_size,

                                                      s->channels, 16);

    }



    init_frame(s);



    copy_samples(s, samples);



    channel_decorrelation(s);



    frame_bytes = encode_frame(s);

    if (buf_size < frame_bytes) {

        av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");

        return 0;

    }

    out_bytes = write_frame(s, frame, buf_size);



    



    if (out_bytes > s->max_framesize) {

        s->frame.verbatim_only = 1;

        frame_bytes = encode_frame(s);

        if (buf_size < frame_bytes) {

            av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");

            return 0;

        }

        out_bytes = write_frame(s, frame, buf_size);

    }



    s->frame_count++;

    avctx->coded_frame->pts = s->sample_count;

    s->sample_count += avctx->frame_size;

    update_md5_sum(s, samples);

    if (out_bytes > s->max_encoded_framesize)

        s->max_encoded_framesize = out_bytes;

    if (out_bytes < s->min_framesize)

        s->min_framesize = out_bytes;



    return out_bytes;

}

static int FUNC_0(AVCodecContext *VAR_0, uint8_t *VAR_1,

                             int VAR_2, void *VAR_3)

{

    FlacEncodeContext *s;

    const int16_t *VAR_4 = VAR_3;

    int VAR_5, VAR_6;



    s = VAR_0->priv_data;



    

    if (!VAR_3) {

        s->max_framesize = s->max_encoded_framesize;

        av_md5_final(s->md5ctx, s->md5sum);

        write_streaminfo(s, VAR_0->extradata);

        return 0;

    }



    

    if (VAR_0->frame_size < s->VAR_1.blocksize) {

        s->max_framesize = ff_flac_get_max_frame_size(VAR_0->frame_size,

                                                      s->channels, 16);

    }



    init_frame(s);



    copy_samples(s, VAR_4);



    channel_decorrelation(s);



    VAR_5 = encode_frame(s);

    if (VAR_2 < VAR_5) {

        av_log(VAR_0, AV_LOG_ERROR, "output buffer too small\n");

        return 0;

    }

    VAR_6 = write_frame(s, VAR_1, VAR_2);



    



    if (VAR_6 > s->max_framesize) {

        s->VAR_1.verbatim_only = 1;

        VAR_5 = encode_frame(s);

        if (VAR_2 < VAR_5) {

            av_log(VAR_0, AV_LOG_ERROR, "output buffer too small\n");

            return 0;

        }

        VAR_6 = write_frame(s, VAR_1, VAR_2);

    }



    s->frame_count++;

    VAR_0->coded_frame->pts = s->sample_count;

    s->sample_count += VAR_0->frame_size;

    update_md5_sum(s, VAR_4);

    if (VAR_6 > s->max_encoded_framesize)

        s->max_encoded_framesize = VAR_6;

    if (VAR_6 < s->min_framesize)

        s->min_framesize = VAR_6;



    return VAR_6;

}

static int FUNC_0(AVCodecContext *VAR_0, uint8_t *VAR_1,
int VAR_2, void *VAR_3)
{ FlacEncodeContext *s; const int16_t *VAR_4 = VAR_3; int VAR_5, VAR_6; s = VAR_0->priv_data; if (!VAR_3) { s->max_framesize = s->max_encoded_framesize; av_md5_final(s->md5ctx, s->md5sum); write_streaminfo(s, VAR_0->extradata); return 0; } if (VAR_0->frame_size < s->VAR_1.blocksize) { s->max_framesize = ff_flac_get_max_frame_size(VAR_0->frame_size,
s->channels, 16); } init_frame(s); copy_samples(s, VAR_4); channel_decorrelation(s); VAR_5 = encode_frame(s); if (VAR_2 < VAR_5) { av_log(VAR_0, AV_LOG_ERROR, "output buffer too small\n"); return 0; } VAR_6 = write_frame(s, VAR_1, VAR_2); if (VAR_6 > s->max_framesize) { s->VAR_1.verbatim_only = 1; VAR_5 = encode_frame(s); if (VAR_2 < VAR_5) { av_log(VAR_0, AV_LOG_ERROR, "output buffer too small\n"); return 0; } VAR_6 = write_frame(s, VAR_1, VAR_2); } s->frame_count++; VAR_0->coded_frame->pts = s->sample_count; s->sample_count += VAR_0->frame_size; update_md5_sum(s, VAR_4); if (VAR_6 > s->max_encoded_framesize)
s->max_encoded_framesize = VAR_6; if (VAR_6 < s->min_framesize)
s->min_framesize = VAR_6; return VAR_6; }