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

                             const AVFrame *frame, int *got_packet_ptr)

{

    G722Context *c = avctx->priv_data;

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

    int nb_samples, out_size, ret;



    out_size = (frame->nb_samples + 1) / 2;

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

        return ret;



    nb_samples = frame->nb_samples - (frame->nb_samples & 1);



    if (avctx->trellis)

        g722_encode_trellis(c, avctx->trellis, avpkt->data, nb_samples, samples);

    else

        g722_encode_no_trellis(c, avpkt->data, nb_samples, samples);



    /* handle last frame with odd frame_size */

    if (nb_samples < frame->nb_samples) {

        int16_t last_samples[2] = { samples[nb_samples], samples[nb_samples] };

        encode_byte(c, &avpkt->data[nb_samples >> 1], last_samples);

    }



    if (frame->pts != AV_NOPTS_VALUE)

        avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);

    *got_packet_ptr = 1;

    return 0;

}

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

                             const AVFrame *frame, int *got_packet_ptr)

{

    G722Context *c = avctx->priv_data;

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

    int nb_samples, out_size, ret;



    out_size = (frame->nb_samples + 1) / 2;

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

        return ret;



    nb_samples = frame->nb_samples - (frame->nb_samples & 1);



    if (avctx->trellis)

        g722_encode_trellis(c, avctx->trellis, avpkt->data, nb_samples, samples);

    else

        g722_encode_no_trellis(c, avpkt->data, nb_samples, samples);



    

    if (nb_samples < frame->nb_samples) {

        int16_t last_samples[2] = { samples[nb_samples], samples[nb_samples] };

        encode_byte(c, &avpkt->data[nb_samples >> 1], last_samples);

    }



    if (frame->pts != AV_NOPTS_VALUE)

        avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);

    *got_packet_ptr = 1;

    return 0;

}

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

                             const AVFrame *VAR_2, int *VAR_3)

{

    G722Context *c = VAR_0->priv_data;

    const int16_t *VAR_4 = (const int16_t *)VAR_2->data[0];

    int VAR_5, VAR_6, VAR_7;



    VAR_6 = (VAR_2->VAR_5 + 1) / 2;

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

        return VAR_7;



    VAR_5 = VAR_2->VAR_5 - (VAR_2->VAR_5 & 1);



    if (VAR_0->trellis)

        g722_encode_trellis(c, VAR_0->trellis, VAR_1->data, VAR_5, VAR_4);

    else

        g722_encode_no_trellis(c, VAR_1->data, VAR_5, VAR_4);



    

    if (VAR_5 < VAR_2->VAR_5) {

        int16_t last_samples[2] = { VAR_4[VAR_5], VAR_4[VAR_5] };

        encode_byte(c, &VAR_1->data[VAR_5 >> 1], last_samples);

    }



    if (VAR_2->pts != AV_NOPTS_VALUE)

        VAR_1->pts = VAR_2->pts - ff_samples_to_time_base(VAR_0, VAR_0->delay);

    *VAR_3 = 1;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ G722Context *c = VAR_0->priv_data; const int16_t *VAR_4 = (const int16_t *)VAR_2->data[0]; int VAR_5, VAR_6, VAR_7; VAR_6 = (VAR_2->VAR_5 + 1) / 2; if ((VAR_7 = ff_alloc_packet2(VAR_0, VAR_1, VAR_6)))
return VAR_7; VAR_5 = VAR_2->VAR_5 - (VAR_2->VAR_5 & 1); if (VAR_0->trellis)
g722_encode_trellis(c, VAR_0->trellis, VAR_1->data, VAR_5, VAR_4); else
g722_encode_no_trellis(c, VAR_1->data, VAR_5, VAR_4); if (VAR_5 < VAR_2->VAR_5) { int16_t last_samples[2] = { VAR_4[VAR_5], VAR_4[VAR_5] }; encode_byte(c, &VAR_1->data[VAR_5 >> 1], last_samples); } if (VAR_2->pts != AV_NOPTS_VALUE)
VAR_1->pts = VAR_2->pts - ff_samples_to_time_base(VAR_0, VAR_0->delay); *VAR_3 = 1; return 0; }