static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                             const AVFrame *frame, int *got_packet_ptr)

{

    FlacEncodeContext *s;

    int frame_bytes, out_bytes, ret;



    s = avctx->priv_data;



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

    if (!frame) {

        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 (frame->nb_samples < s->frame.blocksize) {

        s->max_framesize = ff_flac_get_max_frame_size(frame->nb_samples,

                                                      s->channels,

                                                      avctx->bits_per_raw_sample);

    }



    init_frame(s, frame->nb_samples);



    copy_samples(s, frame->data[0]);



    channel_decorrelation(s);



    remove_wasted_bits(s);



    frame_bytes = encode_frame(s);



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

       would be if encoded uncompressed. */

    if (frame_bytes < 0 || frame_bytes > s->max_framesize) {

        s->frame.verbatim_only = 1;

        frame_bytes = encode_frame(s);

        if (frame_bytes < 0) {

            av_log(avctx, AV_LOG_ERROR, "Bad frame count\n");

            return frame_bytes;

        }

    }



    if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes)))

        return ret;



    out_bytes = write_frame(s, avpkt);



    s->frame_count++;

    s->sample_count += frame->nb_samples;

    if ((ret = update_md5_sum(s, frame->data[0])) < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error updating MD5 checksum\n");

        return ret;

    }

    if (out_bytes > s->max_encoded_framesize)

        s->max_encoded_framesize = out_bytes;

    if (out_bytes < s->min_framesize)

        s->min_framesize = out_bytes;



    avpkt->pts      = frame->pts;

    avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);

    avpkt->size     = out_bytes;

    *got_packet_ptr = 1;

    return 0;

}

static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                             const AVFrame *frame, int *got_packet_ptr)

{

    FlacEncodeContext *s;

    int frame_bytes, out_bytes, ret;



    s = avctx->priv_data;



    

    if (!frame) {

        s->max_framesize = s->max_encoded_framesize;

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

        write_streaminfo(s, avctx->extradata);

        return 0;

    }



    

    if (frame->nb_samples < s->frame.blocksize) {

        s->max_framesize = ff_flac_get_max_frame_size(frame->nb_samples,

                                                      s->channels,

                                                      avctx->bits_per_raw_sample);

    }



    init_frame(s, frame->nb_samples);



    copy_samples(s, frame->data[0]);



    channel_decorrelation(s);



    remove_wasted_bits(s);



    frame_bytes = encode_frame(s);



    



    if (frame_bytes < 0 || frame_bytes > s->max_framesize) {

        s->frame.verbatim_only = 1;

        frame_bytes = encode_frame(s);

        if (frame_bytes < 0) {

            av_log(avctx, AV_LOG_ERROR, "Bad frame count\n");

            return frame_bytes;

        }

    }



    if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes)))

        return ret;



    out_bytes = write_frame(s, avpkt);



    s->frame_count++;

    s->sample_count += frame->nb_samples;

    if ((ret = update_md5_sum(s, frame->data[0])) < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error updating MD5 checksum\n");

        return ret;

    }

    if (out_bytes > s->max_encoded_framesize)

        s->max_encoded_framesize = out_bytes;

    if (out_bytes < s->min_framesize)

        s->min_framesize = out_bytes;



    avpkt->pts      = frame->pts;

    avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);

    avpkt->size     = out_bytes;

    *got_packet_ptr = 1;

    return 0;

}

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

                             const AVFrame *VAR_2, int *VAR_3)

{

    FlacEncodeContext *s;

    int VAR_4, VAR_5, VAR_6;



    s = VAR_0->priv_data;



    

    if (!VAR_2) {

        s->max_framesize = s->max_encoded_framesize;

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

        write_streaminfo(s, VAR_0->extradata);

        return 0;

    }



    

    if (VAR_2->nb_samples < s->VAR_2.blocksize) {

        s->max_framesize = ff_flac_get_max_frame_size(VAR_2->nb_samples,

                                                      s->channels,

                                                      VAR_0->bits_per_raw_sample);

    }



    init_frame(s, VAR_2->nb_samples);



    copy_samples(s, VAR_2->data[0]);



    channel_decorrelation(s);



    remove_wasted_bits(s);



    VAR_4 = encode_frame(s);



    



    if (VAR_4 < 0 || VAR_4 > s->max_framesize) {

        s->VAR_2.verbatim_only = 1;

        VAR_4 = encode_frame(s);

        if (VAR_4 < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Bad VAR_2 count\n");

            return VAR_4;

        }

    }



    if ((VAR_6 = ff_alloc_packet2(VAR_0, VAR_1, VAR_4)))

        return VAR_6;



    VAR_5 = write_frame(s, VAR_1);



    s->frame_count++;

    s->sample_count += VAR_2->nb_samples;

    if ((VAR_6 = update_md5_sum(s, VAR_2->data[0])) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Error updating MD5 checksum\n");

        return VAR_6;

    }

    if (VAR_5 > s->max_encoded_framesize)

        s->max_encoded_framesize = VAR_5;

    if (VAR_5 < s->min_framesize)

        s->min_framesize = VAR_5;



    VAR_1->pts      = VAR_2->pts;

    VAR_1->duration = ff_samples_to_time_base(VAR_0, VAR_2->nb_samples);

    VAR_1->size     = VAR_5;

    *VAR_3 = 1;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ FlacEncodeContext *s; int VAR_4, VAR_5, VAR_6; s = VAR_0->priv_data; if (!VAR_2) { s->max_framesize = s->max_encoded_framesize; av_md5_final(s->md5ctx, s->md5sum); write_streaminfo(s, VAR_0->extradata); return 0; } if (VAR_2->nb_samples < s->VAR_2.blocksize) { s->max_framesize = ff_flac_get_max_frame_size(VAR_2->nb_samples,
s->channels,
VAR_0->bits_per_raw_sample); } init_frame(s, VAR_2->nb_samples); copy_samples(s, VAR_2->data[0]); channel_decorrelation(s); remove_wasted_bits(s); VAR_4 = encode_frame(s); if (VAR_4 < 0 || VAR_4 > s->max_framesize) { s->VAR_2.verbatim_only = 1; VAR_4 = encode_frame(s); if (VAR_4 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Bad VAR_2 count\n"); return VAR_4; } } if ((VAR_6 = ff_alloc_packet2(VAR_0, VAR_1, VAR_4)))
return VAR_6; VAR_5 = write_frame(s, VAR_1); s->frame_count++; s->sample_count += VAR_2->nb_samples; if ((VAR_6 = update_md5_sum(s, VAR_2->data[0])) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error updating MD5 checksum\n"); return VAR_6; } if (VAR_5 > s->max_encoded_framesize)
s->max_encoded_framesize = VAR_5; if (VAR_5 < s->min_framesize)
s->min_framesize = VAR_5; VAR_1->pts      = VAR_2->pts; VAR_1->duration = ff_samples_to_time_base(VAR_0, VAR_2->nb_samples); VAR_1->size     = VAR_5; *VAR_3 = 1; return 0; }