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

                               const AVFrame *frame, int *got_packet_ptr)

{

    AMRContext *s = avctx->priv_data;

    int written, ret;

    int16_t *flush_buf = NULL;

    const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;



    if (s->enc_bitrate != avctx->bit_rate) {

        s->enc_mode    = get_bitrate_mode(avctx->bit_rate, avctx);

        s->enc_bitrate = avctx->bit_rate;

    }



    if ((ret = ff_alloc_packet(avpkt, 32))) {

        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");

        return ret;

    }



    if (frame) {

        if (frame->nb_samples < avctx->frame_size) {

            flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf));

            if (!flush_buf)

                return AVERROR(ENOMEM);

            memcpy(flush_buf, samples, frame->nb_samples * sizeof(*flush_buf));

            samples = flush_buf;

            if (frame->nb_samples < avctx->frame_size - avctx->delay)

                s->enc_last_frame = -1;

        }

        if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) {

            av_freep(&flush_buf);

            return ret;

        }

    } else {

        if (s->enc_last_frame < 0)

            return 0;

        flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf));

        if (!flush_buf)

            return AVERROR(ENOMEM);

        samples = flush_buf;

        s->enc_last_frame = -1;

    }



    written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples,

                                       avpkt->data, 0);

    av_dlog(avctx, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",

            written, s->enc_mode, frame[0]);



    /* Get the next frame pts/duration */

    ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,

                       &avpkt->duration);



    avpkt->size = written;

    *got_packet_ptr = 1;

    av_freep(&flush_buf);

    return 0;

}

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

                               const AVFrame *frame, int *got_packet_ptr)

{

    AMRContext *s = avctx->priv_data;

    int written, ret;

    int16_t *flush_buf = NULL;

    const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;



    if (s->enc_bitrate != avctx->bit_rate) {

        s->enc_mode    = get_bitrate_mode(avctx->bit_rate, avctx);

        s->enc_bitrate = avctx->bit_rate;

    }



    if ((ret = ff_alloc_packet(avpkt, 32))) {

        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");

        return ret;

    }



    if (frame) {

        if (frame->nb_samples < avctx->frame_size) {

            flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf));

            if (!flush_buf)

                return AVERROR(ENOMEM);

            memcpy(flush_buf, samples, frame->nb_samples * sizeof(*flush_buf));

            samples = flush_buf;

            if (frame->nb_samples < avctx->frame_size - avctx->delay)

                s->enc_last_frame = -1;

        }

        if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) {

            av_freep(&flush_buf);

            return ret;

        }

    } else {

        if (s->enc_last_frame < 0)

            return 0;

        flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf));

        if (!flush_buf)

            return AVERROR(ENOMEM);

        samples = flush_buf;

        s->enc_last_frame = -1;

    }



    written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples,

                                       avpkt->data, 0);

    av_dlog(avctx, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",

            written, s->enc_mode, frame[0]);



    

    ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,

                       &avpkt->duration);



    avpkt->size = written;

    *got_packet_ptr = 1;

    av_freep(&flush_buf);

    return 0;

}

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

                               const AVFrame *VAR_2, int *VAR_3)

{

    AMRContext *s = VAR_0->priv_data;

    int VAR_4, VAR_5;

    int16_t *flush_buf = NULL;

    const int16_t *VAR_6 = VAR_2 ? (const int16_t *)VAR_2->data[0] : NULL;



    if (s->enc_bitrate != VAR_0->bit_rate) {

        s->enc_mode    = get_bitrate_mode(VAR_0->bit_rate, VAR_0);

        s->enc_bitrate = VAR_0->bit_rate;

    }



    if ((VAR_5 = ff_alloc_packet(VAR_1, 32))) {

        av_log(VAR_0, AV_LOG_ERROR, "Error getting output packet\n");

        return VAR_5;

    }



    if (VAR_2) {

        if (VAR_2->nb_samples < VAR_0->frame_size) {

            flush_buf = av_mallocz(VAR_0->frame_size * sizeof(*flush_buf));

            if (!flush_buf)

                return AVERROR(ENOMEM);

            memcpy(flush_buf, VAR_6, VAR_2->nb_samples * sizeof(*flush_buf));

            VAR_6 = flush_buf;

            if (VAR_2->nb_samples < VAR_0->frame_size - VAR_0->delay)

                s->enc_last_frame = -1;

        }

        if ((VAR_5 = ff_af_queue_add(&s->afq, VAR_2)) < 0) {

            av_freep(&flush_buf);

            return VAR_5;

        }

    } else {

        if (s->enc_last_frame < 0)

            return 0;

        flush_buf = av_mallocz(VAR_0->frame_size * sizeof(*flush_buf));

        if (!flush_buf)

            return AVERROR(ENOMEM);

        VAR_6 = flush_buf;

        s->enc_last_frame = -1;

    }



    VAR_4 = Encoder_Interface_Encode(s->enc_state, s->enc_mode, VAR_6,

                                       VAR_1->data, 0);

    av_dlog(VAR_0, "FUNC_0 encoded %u bytes, bitrate %u, first byte was %#02x\n",

            VAR_4, s->enc_mode, VAR_2[0]);



    

    ff_af_queue_remove(&s->afq, VAR_0->frame_size, &VAR_1->pts,

                       &VAR_1->duration);



    VAR_1->size = VAR_4;

    *VAR_3 = 1;

    av_freep(&flush_buf);

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ AMRContext *s = VAR_0->priv_data; int VAR_4, VAR_5; int16_t *flush_buf = NULL; const int16_t *VAR_6 = VAR_2 ? (const int16_t *)VAR_2->data[0] : NULL; if (s->enc_bitrate != VAR_0->bit_rate) { s->enc_mode    = get_bitrate_mode(VAR_0->bit_rate, VAR_0); s->enc_bitrate = VAR_0->bit_rate; } if ((VAR_5 = ff_alloc_packet(VAR_1, 32))) { av_log(VAR_0, AV_LOG_ERROR, "Error getting output packet\n"); return VAR_5; } if (VAR_2) { if (VAR_2->nb_samples < VAR_0->frame_size) { flush_buf = av_mallocz(VAR_0->frame_size * sizeof(*flush_buf)); if (!flush_buf)
return AVERROR(ENOMEM); memcpy(flush_buf, VAR_6, VAR_2->nb_samples * sizeof(*flush_buf)); VAR_6 = flush_buf; if (VAR_2->nb_samples < VAR_0->frame_size - VAR_0->delay)
s->enc_last_frame = -1; } if ((VAR_5 = ff_af_queue_add(&s->afq, VAR_2)) < 0) { av_freep(&flush_buf); return VAR_5; } } else { if (s->enc_last_frame < 0)
return 0; flush_buf = av_mallocz(VAR_0->frame_size * sizeof(*flush_buf)); if (!flush_buf)
return AVERROR(ENOMEM); VAR_6 = flush_buf; s->enc_last_frame = -1; } VAR_4 = Encoder_Interface_Encode(s->enc_state, s->enc_mode, VAR_6,
VAR_1->data, 0); av_dlog(VAR_0, "FUNC_0 encoded %u bytes, bitrate %u, first byte was %#02x\n",
VAR_4, s->enc_mode, VAR_2[0]); ff_af_queue_remove(&s->afq, VAR_0->frame_size, &VAR_1->pts,
&VAR_1->duration); VAR_1->size = VAR_4; *VAR_3 = 1; av_freep(&flush_buf); return 0; }